ventrue.w
(usa Debian)
Enviado em 30/03/2009 - 12:11h
vo posta aqui.. mas mesmo ele estando desabilitado o problema acontece...
#!/bin/bash
parar(){
####################################################
#Apaga Regras carregadas anteriormente
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -F -t nat
iptables -X -t nat
iptables -F -t mangle
iptables -X -t mangle
iptables -X
iptables -Z
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
echo "FIREWALL DESATIVADO"
####################################################
}
iniciar(){
# Ativa roteamento do Kernel
echo "1" > /proc/sys/net/ipv4/ip_forward
# Protecao contra IP Spoofing
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
# Politicas de segurançs CHAINS INPUT, OUTPUT e FORWARD, FORWARD liberado porque ninguem fora vai conseguir entar por causa do INPUT
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
# Regras de PING
iptables -A INPUT -p icmp --icmp-type 0 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-reply -m limit --limit 1/s -j RETURN
iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT
#Libera o loopback
iptables -A OUTPUT -p tcp --syn -s 127.0.0.1/255.0.0.0 -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
# Configura o PORTMAP/NFS/BIND9
iptables -A INPUT -p tcp -s 127.0.0.1 --dport 111 -j ACCEPT
iptables -A INPUT -p udp -s 127.0.0.1 --dport 111 -j ACCEPT
iptables -A INPUT -p tcp -s 127.0.0.1 --dport 53 -j ACCEPT
iptables -A INPUT -p tcp -s 127.0.0.1 --dport 953 -j ACCEPT
iptables -A INPUT -p tcp -i eth1 --syn --dport 111 -j DROP
# REGRAS POSTGRESQL
iptables -A INPUT -p tcp --dport 5432 -j ACCEPT
# Libera apache porta 80 do firewall na interface eth1 (web)
iptables -A INPUT -i eth1 -p tcp -m tcp --dport 80 -j ACCEPT
# Todo trafego de rede na placa eth1 (web) tem prioridade na porta 80
iptables -t mangle -A INPUT -i eth1 -p tcp --dport 80 -j TOS --set-tos 16
# Bloqueia POrta 22 eth1
iptables -A INPUT -i eth1 -p tcp -m tcp --dport 22 -j DROP
# Relogio
iptables -A INPUT -p udp -s 127.0.0.1 --dport 123 -j ACCEPT
iptables -A INPUT -i eth1 -p udp --dport 123 -j ACCEPT
# Pacotes de retorno da WEB
iptables -A INPUT -i! eth1 -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
# DROP e LOG de Port Scanners
iptables -N SCANNER
iptables -A SCANNER -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "DIVERSOS: port scanner:"
iptables -A SCANNER -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL NONE -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL ALL -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i eth1 -j SCANNER
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i eth1 -j SCANNER
# LOG de Acesso por portas
iptables -A INPUT -p tcp --dport 21 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: ftp"
iptables -A INPUT -p tcp --dport ***** -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: ssh - web"
iptables -A INPUT -p udp --dport 69 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: tftp"
iptables -A INPUT -p tcp --dport 23 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: telnet"
iptables -A INPUT -p tcp --dport 25 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: smtp"
iptables -A INPUT -p tcp --dport 80 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: http"
iptables -A INPUT -p tcp --dport 110 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: pop3"
iptables -A INPUT -p udp --dport 111 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: rpc"
iptables -A INPUT -p tcp --dport 161:162 -i eth1 -j LOG --log-level 6 --log-prefix "FIREWALL: snmp"
# Estabelece relacao de confianca para rede local, todas as conexoes que entrarem pela eth0 (rede local) de uma maquina da classe 192.168.0.0 devem ser aceitas sem restricoes
iptables -A INPUT -i eth0 -s 192.168.0.0/24 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Libera o SSH na eth1 (web) para qualquer IP
iptables -A INPUT -i eth1 -p tcp -m tcp --dport ***** -j ACCEPT
#########################################################################################################
# Nega tudo que nao for permitido acima
#iptables -A INPUT -i eth1 -j REJECT
##########################################################################################################
# Regras contra BRUTE FORCE SSH
iptables -A INPUT -p tcp --syn --dport *** -m recent --name sshattack --set
iptables -A INPUT -p tcp --dport **** --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j LOG --log-prefix "FIREWALL: SSH REJECT"
iptables -A INPUT -p tcp --dport **** --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j REJECT --reject-with tcp-reset
iptables -A FORWARD -p tcp --syn --dport **** -m recent --name sshattack --set
iptables -A FORWARD -p tcp --dport **** --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j LOG --log-prefix "FIREWALL: SSH REJECT"
iptables -A FORWARD -p tcp --dport **** --syn -m recent --name sshattack --rcheck --seconds 60 --hitcount 3 -j REJECT --reject-with tcp-reset
# Redireciona todas as tentativas de conexoes da rede local a www.**.******.br para os servidores locais
iptables -t nat -A PREROUTING -s 192.168.0.0/24 -d www.**.*****.br -p tcp -m tcp -j DNAT --to 192.168.0.199
}
case "$1" in
"start") iniciar ;;
"stop") parar ;;
"restart") parar; iniciar ;;
*) echo "Use os parametros START ou STOP"
esac