Enviado em 24/04/2013 - 08:37h
Turma,
#!/bin/bash
#Declaracao das variaveis
TCP_SAFE=53,80,138,8080,443,3389,3128,993,995,25,110,587,465,5555,5389
TRIX_PORT=2101
UDP_SAFE=53,137,138
iniciar(){
modprobe iptable_nat
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
#Mudando o estado das Chains
iptables -P INPUT DROP
iptables -P FORWARD DROP
#Ativando compartilhamento
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
#Gravando logs da forward
iptables -A FORWARD -j LOG
#Bloqueio de maquinas via mac
iptables -A FORWARD -p tcp -m mac --mac-source 94:39:e5:f2:69:93 -j DROP
iptables -A FORWARD -p tcp -m mac --mac-source e0:b9:a5:21:ac:ff -j DROP
iptables -A FORWARD -p tcp -m mac --mac-source 14:da:e9:b8:9a:18 -j DROP
#Ativando proxy transparente
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128
#iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 443 -j REDIRECT --to-port 3128
#bloqueando Ping
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
#Liberando trafego na lookback e Rede Interna
iptables -A INPUT -i ! lo -s 127.0.0.0/0.0.0.0 -j DROP
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT
#Liberando ping seguro
#iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
#Liberando conexoes e portas seguras na INPUT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports $TCP_SAFE -j ACCEPT
iptables -A INPUT -p udp -m multiport --dports $UDP_SAFE -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports $TRIX_PORT -j ACCEPT
#Bloqueio direto de sites HTTP e HTTPS
iptables -A FORWARD -m string --algo bm --string "facebook.com" -j DROP
iptables -A FORWARD -m string --algo bm --string "youtube.com" -j DROP
iptables -A FORWARD -m string --algo bm --string "twitter.com" -j DROP
#Liberando conexoes e portas seguras na FORWARD
iptables -A FORWARD -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -p tcp -m multiport --dports $TCP_SAFE -j ACCEPT
iptables -A FORWARD -p udp -m multiport --dports $UDP_SAFE -j ACCEPT
iptables -A FORWARD -p tcp -m multiport --dports $TRIX_PORT -j ACCEPT
#Tentado dropar porta do ULTRASURF
iptables -A FORWARD -i eth1 -p tcp --dport 9666 -j DROP
#iptables -A FORWARD -j DROP
echo "Regras de firewall e compartilhamento de internet ativado"
}
parar(){
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -F
iptables -F
echo "Regras de firewall desativadas"
}
case "$1" in
"start") iniciar ;;
"stop") parar ;;
"restart") parar; iniciar ;;
*) echo "Use os parâtros start ou stop"
esac