glaucoperucchi
(usa Debian)
Enviado em 31/10/2013 - 08:37h
Ainda não deu certo, agora o Itau não deixa eu realizar pagamento porque diz que a rede apresenta risco, acredito que seja por esse problema que está dando.
Abaixo meu script:
#!/bin/bash
firewall_start () {
clear
### Definição de Variáveis
# Define o local do binário do Iptables
CHipt="/sbin/iptables"
# Definindo Variáveis do Firewall
CHlan=eth0
CHrede0=192.168.25.0/255.255.255.0
### Carrega Módulos iptables
modprobe ip_tables
modprobe iptable_filter
modprobe iptable_mangle
modprobe iptable_nat
modprobe ipt_MASQUERADE
modprobe ip_nat_ftp
modprobe ip_conntrack_ftp
modprobe ip_conntrack_irc
modprobe ip_conntrack
modprobe xt_layer7
### Limpa todas as regras do Iptables
$CHipt -X
$CHipt -F
$CHipt -Z
$CHipt -F INPUT
$CHipt -F OUTPUT
$CHipt -F FORWARD
$CHipt -F -t nat
$CHipt -F -t mangle
# Aceita todas as Conexões para Interface loopback
$CHipt -A INPUT -i lo -j ACCEPT
### Define Política Padrão das Cadeiras
$CHipt -P INPUT DROP
$CHipt -P FORWARD DROP
$CHipt -P OUTPUT ACCEPT
### LOG
$CHipt -A INPUT -j LOG
$CHipt -A INPUT -p tcp --dport 22 -j LOG --log-prefix "Acesso SSH "
$CHipt -A INPUT -p tcp --dport 80 -j LOG --log-prefix "Acesso ao Web "
$CHipt -A INPUT -p tcp --dport 8888 -j LOG --log-prefix "Acesso ao Web "
$CHipt -A INPUT -p tcp --dport 8080 -j LOG --log-prefix "Acesso ao Web "
$CHipt -A INPUT -p tcp --dport 8081 -j LOG --log-prefix "Acesso ao Web "
### Liberar IP sem passar por proxy
$CHipt -I FORWARD -s 192.168.25.24 -j ACCEPT #Jady
$CHipt -t nat -I PREROUTING -s 192.168.25.24 -p tcp --dport 80 -j ACCEPT #Jady
$CHipt -t nat -I PREROUTING -s 192.168.25.24 -p tcp --dport 443 -j ACCEPT #Jady
$CHipt -t nat -A PREROUTING -i $CHlan -s 192.168.25.24 -p tcp --dport 443 -j ACCEPT #Jady
$CHipt -I FORWARD -s 192.168.25.52 -j ACCEPT #Camila
$CHipt -t nat -I PREROUTING -s 192.168.25.52 -p tcp --dport 80 -j ACCEPT #Camila
$CHipt -t nat -I PREROUTING -s 192.168.25.52 -p tcp --dport 443 -j ACCEPT #Camila
$CHipt -t nat -A PREROUTING -i $CHlan -s 192.168.25.52 -p tcp --dport 443 -j ACCEPT #Camila
### Bloquear acesso HTTPS
$CHipt -A FORWARD -p tcp --dport 443 -j DROP
$CHipt -I FORWARD -d 200.248.92.23 -p tcp --dport 443 -j ACCEPT #Portal lojas Renner
$CHipt -I FORWARD -d 200.198.128.51 -p tcp --dport 443 -j ACCEPT #Sefaz RS
$CHipt -I FORWARD -d 200.233.3.230 -p tcp --dport 443 -j ACCEPT #MDF Sefaz RS
$CHipt -I FORWARD -d 200.233.3.102 -p tcp --dport 443 -j ACCEPT #NFe Sefaz RS
$CHipt -I FORWARD -d 170.66.11.10 -p tcp --dport 443 -j ACCEPT #Banco do Brasil
$CHipt -I FORWARD -d 170.66.2.59 -p tcp --dport 443 -j ACCEPT #Banco do Brasil
$CHipt -I FORWARD -d 170.66.52.28 -p tcp --dport 443 -j ACCEPT #Banco do Brasil
$CHipt -I FORWARD -d 170.66.1.60 -p tcp --dport 443 -j ACCEPT #Banco do Brasil
$CHipt -I FORWARD -d 177.99.179.0/24 -p tcp --dport 443 -j ACCEPT #Google
$CHipt -I FORWARD -d 177.99.189.0/24 -p tcp --dport 443 -j ACCEPT #Google
### Liberar acesso HTTPS para IP
$CHipt -I FORWARD -s 192.168.25.25 -p tcp --dport 443 -j ACCEPT #Fran
$CHipt -I FORWARD -s 192.168.25.21 -p tcp --dport 443 -j ACCEPT #Alexandre
$CHipt -I FORWARD -s 192.168.25.60 -p tcp --dport 443 -j ACCEPT #Lediane
$CHipt -I FORWARD -s 192.168.25.52 -p tcp --dport 443 -j ACCEPT #Camila
$CHipt -I FORWARD -s 192.168.25.20 -p tcp --dport 443 -j ACCEPT #Felipe
$CHipt -I FORWARD -s 192.168.25.13 -p tcp --dport 443 -j ACCEPT #Ana - PCP
$CHipt -I FORWARD -s 192.168.25.203 -p tcp --dport 443 -j ACCEPT #Ana Franco
$CHipt -I FORWARD -s 192.168.25.254 -p tcp --dport 443 -j ACCEPT #Servidor
$CHipt -I FORWARD -s 192.168.25.79 -p tcp --dport 443 -j ACCEPT #Auditor
$CHipt -I FORWARD -s 192.168.25.204 -p tcp --dport 443 -j ACCEPT #Cicera
$CHipt -I FORWARD -s 192.168.25.61 -p tcp --dport 443 -j ACCEPT #Fabinote
$CHipt -I FORWARD -s 192.168.25.89 -p tcp --dport 443 -j ACCEPT #Jady Cel
### Liberar acesso Skype para IP
#$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto skypeout -j DROP
#$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto skypetoskype -j DROP
### Manter conexões estabelecidas para não parar
$CHipt -A INPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$CHipt -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
$CHipt -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# Proteção para SYN Flood
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
#iptables -A FORWARD -i $CHwan ! -s $CHrede0 -j DROP
# Rejeitar requisição de ICMP Echo
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
# Rejeitar requisição de ICMP Echo destinado a Broadcasts e Multicasts
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Ignorar Mensagens Falsas de icmp_error_responses
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
for i in /proc/sys/net/ipv4/conf/*; do
# Não Redirecionar Mensagens ICMP
echo 0 > $i/accept_redirects
# Proteção a Ataques IP Spoofing
echo 0 > $i/accept_source_route
# Permitir que Pacotes Forjados sejam logados pelo próprio kernel
echo 1 > $i/log_martians
# Verificar Endereço de Origem do Pacote (Proteção a Ataques IP Spoofing)
echo 1 > $i/rp_filter
done
### Configura Proteção Contra PortScan Ocultos
$CHipt -N SCANNER
$CHipt -A SCANNER -j DROP
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "FIN,URG,PSH"
$CHipt -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i $CHlan -j SCANNER
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags ALL NONE -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "NULL Packets"
$CHipt -A INPUT -p tcp --tcp-flags ALL NONE -i $CHlan -j SCANNER
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags ALL ALL -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "ALL Packets"
$CHipt -A INPUT -p tcp --tcp-flags ALL ALL -i $CHlan -j SCANNER
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags ALL FIN,SYN -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "ALL FIN,SYN"
$CHipt -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i $CHlan -j SCANNER
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "SYN,RST"
$CHipt -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i $CHlan -j SCANNER
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "XMAS Packets"
$CHipt -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i $CHlan -j SCANNER
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags FIN,ACK FIN -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "FIN Packets Scan"
$CHipt -A INPUT -p tcp --tcp-flags FIN,ACK FIN -i $CHlan -j SCANNER
$CHipt -A INPUT -i $CHlan -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "ALL SYN,RST,ACK,FIN,URG"
$CHipt -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i $CHlan -j SCANNER
# Torrent
#$CHipt -A FORWARD -s 192.168.0.xxx -m layer7 --l7proto bittorrent -j ACCEPT
$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto bittorrent -j DROP
$CHipt -A FORWARD -d 0/0 -m layer7 --l7proto bittorrent -j DROP
$CHipt -A FORWARD -s 0/0 -p tcp --destination-port 6881:65535 -j DROP
$CHipt -A INPUT -s 0/0 -p tcp --destination-port 6881:65535 -j DROP
# Ares
$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto ares -j DROP
$CHipt -A FORWARD -d 0/0 -m layer7 --l7proto ares -j DROP
# Emule
$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto edonkey -j DROP
$CHipt -A FORWARD -d 0/0 -m layer7 --l7proto edonkey -j DROP
# iMesh
$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto imesh -j DROP
$CHipt -A FORWARD -d 0/0 -m layer7 --l7proto imesh -j DROP
# Napster
$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto napster -j DROP
$CHipt -A FORWARD -d 0/0 -m layer7 --l7proto napster -j DROP
# Tor
$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto tor -j DROP
$CHipt -A FORWARD -d 0/0 -m layer7 --l7proto tor -j DROP
# WinMX
$CHipt -A FORWARD -d 209.61.186.0/24 -j DROP
$CHipt -A FORWARD -d 64.49.201.0/24 -j DROP
# Napigator
$CHipt -A FORWARD -d 209.25.178.0/24 -j DROP
# Morpheus
$CHipt -A FORWARD -d 206.142.53.0/24 -j DROP
# KaZaA
$CHipt -A FORWARD -d 213.248.112.0/24 -j DROP
# Audiogalaxy
$CHipt -A FORWARD -s 0/0 -m layer7 --l7proto audiogalaxy -j DROP
$CHipt -A FORWARD -d 0/0 -m layer7 --l7proto audiogalaxy -j DROP
### Bloqueia TraceRoute
$CHipt -A INPUT -p udp -s 0/0 -i $CHlan --dport 33435:33525 -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "Trace Route"
$CHipt -A INPUT -p udp -s 0/0 -i $CHlan --dport 33435:33525 -j DROP
$CHipt -A FORWARD -p udp -s 0/0 -i $CHlan --dport 33435:33525 -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "Trace Route"
$CHipt -A FORWARD -p udp -s 0/0 -i $CHlan --dport 33435:33525 -j DROP
### Bloqueia Ataques DoS
$CHipt -A INPUT -m state --state INVALID -j DROP
$CHipt -A FORWARD -m state --state INVALID -j DROP
$CHipt -A OUTPUT -p tcp ! --tcp-flags SYN,RST,ACK SYN -m state --state NEW -j DROP
### Proteção Contra Ping da Morte
$CHipt -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
$CHipt -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
$CHipt -A INPUT -p icmp --icmp-type echo-reply -m limit --limit 1/s -j DROP
$CHipt -A FORWARD -p icmp --icmp-type echo-reply -m limit --limit 1/s -j DROP
### Proteção Contra Syn
$CHipt -A INPUT -i $CHlan -p tcp ! --syn -m state --state NEW -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "Drop Syn"
$CHipt -A INPUT -i $CHlan -p tcp ! --syn -m state --state NEW -j DROP
### Proteção Contra Fragmentos
$CHipt -A INPUT -i $CHlan -f -m limit --limit 5/m --limit-burst 7 -j LOG --log-level 4 --log-prefix "Fragments Packets"
$CHipt -A INPUT -i $CHlan -f -j DROP
# Liberação sites internos
$CHipt -A FORWARD -s $CHrede0 -j ACCEPT
$CHipt -A INPUT -s $CHrede0 -j ACCEPT
$CHipt -A OUTPUT -s $CHrede0 -j ACCEPT
### Redireciona HTTP para Squid
$CHipt -t nat -F POSTROUTING
$CHipt -t nat -A POSTROUTING -o $CHlan -j MASQUERADE
$CHipt -t nat -A PREROUTING -i $CHlan -p tcp --dport 80 -j REDIRECT --to-ports 3128
### Redirecionamento do MSN para Squid
$CHipt -t nat -I PREROUTING -i $CHlan -p tcp --dport 1863 -j REDIRECT --to-ports 1863
### Redirecionamento de Portas Específicas
$CHipt -t nat -A PREROUTING -i $CHlan -p tcp --dport 3306 -j DNAT --to 192.168.25.254:3306
$CHipt -t nat -A PREROUTING -i $CHlan -p tcp --dport 8888 -j DNAT --to 192.168.25.254:8888
### Liberação de portas
$CHipt -A FORWARD -i $CHlan -p tcp --dport 110 -j ACCEPT #POP3
$CHipt -A FORWARD -i $CHlan -p tcp --dport 25 -j ACCEPT #SMTP
$CHipt -A FORWARD -i $CHlan -p tcp --dport 53 -j ACCEPT #DNS
$CHipt -A FORWARD -i $CHlan -p tcp --dport 22 -j ACCEPT #SSH
$CHipt -A FORWARD -i $CHlan -p tcp --dport 3306 -j ACCEPT #MySQL
$CHipt -A FORWARD -i $CHlan -p tcp --dport 8888 -j ACCEPT #Apache2
$CHipt -A FORWARD -i $CHlan -p tcp --dport 993 -j ACCEPT #IMAP
$CHipt -A FORWARD -i $CHlan -p tcp --dport 995 -j ACCEPT #POP3S
$CHipt -A FORWARD -i $CHlan -p tcp --dport 465 -j ACCEPT #SSMTP
$CHipt -A FORWARD -i $CHlan -p tcp --dport 143 -j ACCEPT #IMAP2
$CHipt -A FORWARD -i $CHlan -p tcp --dport 587 -j ACCEPT #SSMTP
$CHipt -A FORWARD -i $CHlan -p tcp --dport 9102 -j ACCEPT #Bacula Cliente
$CHipt -A FORWARD -i $CHlan -p tcp --dport 9103 -j ACCEPT #Bacula terminal
### Liberação do Ping
$CHipt -A INPUT -i $CHlan -p icmp --icmp-type 8 -j ACCEPT
$CHipt -A FORWARD -o $CHlan -p icmp --icmp-type 8 -j ACCEPT
### Log de Bloqueio Padrão
$CHipt -A FORWARD -m limit --limit 2/m -j LOG --log-prefix "FORWARD: Bloqueio Padrao "
$CHipt -A FORWARD -j DROP
$CHipt -A INPUT -p tcp -m multiport ! --dports 0:1056 -j DROP
$CHipt -A INPUT -p udp -j DROP
$CHipt -A INPUT -p icmp -j DROP
$CHipt -A INPUT -m limit --limit 3/m --limit-burst 3 -j LOG --log-prefix "LOG-FW: "
### Habilita tráfego IP entre as interfaces de rede
echo 1 > /proc/sys/net/ipv4/ip_forward
### Bloqueia tudo o que não tenha sido anteriormente declarado como regra
$CHipt -A INPUT -p tcp --syn -j DROP
}
firewall_restart() {
firewall_stop
firewall_start
}
firewall_stop() {
clear
CHipt="/sbin/iptables"
# Interfaces
CHwan=eth1
CHlan=eth0
### Retorna aao padrão das cadeias
$CHipt -P INPUT ACCEPT
$CHipt -P FORWARD ACCEPT
$CHipt -P OUTPUT ACCEPT
### Limpa as Regras de Firewall
$CHipt -Z
$CHipt -F INPUT
$CHipt -F OUTPUT
$CHipt -F FORWARD
$CHipt -F SCANNER
$CHipt -t nat -F
$CHipt -t mangle -F
for spoofing in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "0" > $spoofing
done
echo 1 > /proc/sys/net/ipv4/conf/all/accept_source_route
echo 0 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 0 > /proc/sys/net/ipv4/tcp_syncookies
### Reativação do Mascaramento IP
$CHipt -t nat -F POSTROUTING
$CHipt -t nat -A POSTROUTING -o $CHlan -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
}
case "$1" in
'start')
firewall_start
;;
'stop')
firewall_stop
;;
'restart')
firewall_restart
;;
*)
firewall_start
esac