doidopb
(usa Outra)
Enviado em 10/04/2012 - 22:05h
Squid Cache: Version 2.7.STABLE9
FIREWAL:::
iniciar (){
# DECLARANDO VARIAVEIS #
IPT=iptables
LAN=eth1
WAN=eth0
SEMFA=192.168.10.0/24
SEMDEC=192.168.20.0/24
SEMAD=192.168.30.0/24
SMCT=192.168.40.0/24
PGM=192.168.50.0/24
SEMUC=192.168.60.0/24
SEMPOPO=192.168.70.0/24
SECOM=192.168.80.0/24
SEMUG=192.168.90.0/24
LAPTOP=192.168.110.0/24
SMTJ=192.168.120.0/24
# COMPARTILHANDO INTERNET #
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -t nat -A POSTROUTING -d 192.168.100.0/24 -j MASQUERADE
# CARREGANDO MODULOS #
modprobe iptable_nat
modprobe sch_htb
modprobe sch_sfq
modprobe cls_u32
# DEFAULT POLICE #
$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
# ROTA PARA OS SERVIDORES #
route add -net 192.168.100.0/24 gw 192.167.1.1
# CONFIGURACOES DE SEGURANCA #
echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
$IPT -A INPUT -m state --state INVALID -j DROP
$IPT -A FORWARD -p tcp --syn -m limit --limit 1/s -j ACCEPT
$IPT -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
# FIREWALL MODE STATEFULL
$IPT -A INPUT -p TCP -j ACCEPT -s 0.0.0.0/0 -m state --state ESTABLISHED,RELATED
$IPT -A INPUT -p UDP -j ACCEPT -s 0.0.0.0/0 -m state --state ESTABLISHED,RELATED
$IPT -A FORWARD -m state --state INVALID -j DROP
$IPT -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
# CRIANDO SUBREDES #
ifconfig eth0:10 192.168.10.1 netmask 255.255.255.0 up # SEMFA
ifconfig eth0:20 192.168.20.1 netmask 255.255.255.0 up # SEMDEC
ifconfig eth0:30 192.168.30.1 netmask 255.255.255.0 up # SEMAD
ifconfig eth0:40 192.168.40.1 netmask 255.255.255.0 up # SMCT
ifconfig eth0:50 192.168.50.1 netmask 255.255.255.0 up # PGM
ifconfig eth0:60 192.168.60.1 netmask 255.255.255.0 up # SEMUC
ifconfig eth0:70 192.168.70.1 netmask 255.255.255.0 up # SEMPOPO
ifconfig eth0:80 192.168.80.1 netmask 255.255.255.0 up # SECOM
ifconfig eth0:90 192.168.90.1 netmask 255.255.255.0 up # SEMUG
ifconfig eth0:110 192.168.110.1 netmask 255.255.255.0 up # LAPTOP
ifconfig eth0:120 192.168.120.1 netmask 255.255.255.0 up # SMTJ
#ifconfig eth0:100 192.168.100.253 netmask 255.255.255.0 up # DMZ2
# SQUID TRANSPARENTE #
$IPT -t nat -A PREROUTING -s $SEMFA -p tcp --dport 80 -j REDIRECT --to-port 3128
#$IPT -t nat -A PREROUTING -s $SEMDEC -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $SEMAD -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $SMCT -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $PGM -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $SEMUC -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $SEMPOPO -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $SECOM -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $SEMUG -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $LAPTOP -p tcp --dport 80 -j REDIRECT --to-port 3128
$IPT -t nat -A PREROUTING -s $SMTJ -p tcp --dport 80 -j REDIRECT --to-port 3128
# BLOQUEAR 192.168.70.43 QUE EU NAO SEI QUEM E
iptables -I FORWARD -s 192.168.70.43 -j DROP
iptables -I FORWARD -s 192.168.70.45 -j DROP
# LIBERANDO MESSENGER #
$IPT -A FORWARD -s 192.168.90.2 -m string --algo bm --string "messenger" -j ACCEPT # JUBBER
$IPT -A FORWARD -s 192.168.90.3 -m string --algo bm --string "messenger" -j ACCEPT #
$IPT -A FORWARD -s 192.168.90.4 -m string --algo bm --string "messenger" -j ACCEPT #
$IPT -A FORWARD -s 192.168.90.5 -m string --algo bm --string "messenger" -j ACCEPT #
$IPT -A FORWARD -s 192.168.90.6 -m string --algo bm --string "messenger" -j ACCEPT # SEMUG-GAB-05
$IPT -A FORWARD -s 192.168.90.18 -m string --algo bm --string "messenger" -j ACCEPT # SEMUG-GAB-02
$IPT -A FORWARD -s 192.168.90.20 -m string --algo bm --string "messenger" -j ACCEPT # SEMUG-GAB-04
$IPT -A FORWARD -s 192.168.70.9 -m string --algo bm --string "messenger" -j ACCEPT # CRISTINA-NOTEBO
$IPT -A FORWARD -s 192.168.70.19 -m string --algo bm --string "messenger" -j ACCEPT # TIAGUINHO
$IPT -A FORWARD -s 192.168.30.31 -m string --algo bm --string "messenger" -j ACCEPT # SEMAD-GAB-01
$IPT -A FORWARD -s 192.168.30.115 -m string --algo bm --string "messenger" -j ACCEPT # SEMAD-CRH-14
$IPT -A FORWARD -s 192.168.20.21 -m string --algo bm --string "messenger" -j ACCEPT # LAPTOP SUETH
$IPT -A FORWARD -s 192.168.40.50 -m string --algo bm --string "messenger" -j ACCEPT # GABRIEL
$IPT -A FORWARD -s 192.168.40.175 -m string --algo bm --string "messenger" -j ACCEPT # RICKSON GRACIE BRABOOOOOOOOOOOOO
$IPT -A FORWARD -s 192.168.40.170 -m string --algo bm --string "messenger" -j ACCEPT # SMCT-GAB-01
$IPT -A FORWARD -s 192.168.40.202 -m string --algo bm --string "messenger" -j ACCEPT # LAPTOP FABRICIO
$IPT -A FORWARD -s 192.168.40.198 -m string --algo bm --string "messenger" -j ACCEPT # LAPTOP ANGELA
$IPT -A FORWARD -s 192.168.40.99 -m string --algo bm --string "messenger" -j ACCEPT # MAQUINA CAROL-SMCT
$IPT -A FORWARD -s 192.168.60.19 -m string --algo bm --string "messenger" -j ACCEPT # MAZINHA
$IPT -A FORWARD -s 192.168.90.41 -m string --algo bm --string "messenger" -j ACCEPT # RAQUEL
$IPT -A FORWARD -s 192.168.40.56 -m string --algo bm --string "messenger" -j ACCEPT
# BLOEQUEANDO GTALK & MESSENGER #
$IPT -A FORWARD -s $SEMFA -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SEMDEC -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SEMAD -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SMCT -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $PGM -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SEMUC -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SEMPOPO -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SEMUG -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $LAPTOP -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SMTJ -m string --algo bm --string "chatenabled" -j DROP
$IPT -A FORWARD -s $SEMFA -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $SEMDEC -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $SEMAD -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $SMCT -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $PGM -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $SEMUC -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $SEMPOPO -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $SEMUG -m string --algo bm --string "messenger" -j DROP
$IPT -A FORWARD -s $SMTJ -m string --algo bm --string "messenger" -j DROP
# LIBERANDO FORWARD ENTRE INTERFACES/REDES #
$IPT -A FORWARD -i $LAN -o $WAN -j ACCEPT
$IPT -A FORWARD -o $LAN -i $WAN -j ACCEPT
$IPT -A FORWARD -i $LAN -d 192.168.100.0/24 -j ACCEPT
$IPT -A FORWARD -o $LAN -s 192.168.100.0/24 -j ACCEPT
$IPT -A FORWARD -i $LAN -d 192.167.1.0/24 -j ACCEPT
$IPT -A FORWARD -o $LAN -s 192.167.1.0/24 -j ACCEPT
$IPT -A FORWARD -i $LAN -p icmp -j ACCEPT
# LIBERANDO PORTAS DE ENTRADA #
$IPT -A INPUT -i lo -j ACCEPT # LOOPBACK
$IPT -A INPUT -i $LAN -p icmp -j ACCEPT # ICMP
$IPT -A INPUT -i $LAN -p tcp --dport 80 -s 192.167.1.1 -j ACCEPT # HTTP
$IPT -A INPUT -i $LAN -p udp --dport 161 -s 192.167.1.1 -j ACCEPT # SNMP
$IPT -A INPUT -i $LAN -p tcp --dport 2812 -s 192.167.1.1 -j ACCEPT # MONIT
$IPT -A INPUT -i $LAN -p tcp --dport 443 -j ACCEPT # HTTPS
$IPT -A INPUT -p tcp --dport 55222 -j ACCEPT # SSHD
$IPT -A INPUT -i $LAN -p tcp --dport 3128 -j ACCEPT # SQUID
$IPT -A INPUT -i $LAN -p tcp --dport 3306 -j ACCEPT # MYSQL
echo "Starting firewall: done."
}
parar (){
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
route del -net 192.168.100.0/24 gw 192.167.1.1
echo -e "Stopping firewall: done."
}
case "$1" in
"start") iniciar ;;
"stop") parar ;;
"restart") parar; iniciar ;;
esac