eduardo_jst
(usa Slackware)
Enviado em 06/07/2011 - 11:16h
Primeiramente, obrigado pela atenção.
iptables:
#!/bin/sh
# Variáveis
# -------------------------------------------------------
iptables=/sbin/iptables
IF_EXTERNA=eth1
IF_INTERNA=eth0
# Ativa módulos
# -------------------------------------------------------
/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
# Ativa roteamento no kernel
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/ip_forward
# Proteção contra IP spoofing
# -------------------------------------------------------
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
# Zera regras
# -------------------------------------------------------
$iptables -F
$iptables -X
$iptables -F -t nat
$iptables -X -t nat
$iptables -F -t mangle
$iptables -X -t mangle
# Determina a política padrão
# -------------------------------------------------------
$iptables -P INPUT DROP
$iptables -P OUTPUT DROP
$iptables -P FORWARD DROP
#$iptables -t filter -A INPUT -p tcp --dport 443 -j DROP
$iptables -t filter -A FORWARD -p tcp --dport 443 -j DROP
#$iptables -t filter -A OUTPUT -p tcp --dport 443 -j DROP
#################################################
# Tabela FILTER
#################################################
# Dropa pacotes TCP indesejáveis
# -------------------------------------------------------
$iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j LOG --log-level 6 --log-prefix "FIRE: NEW sem syn: "
$iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP
# Dropa pacotes mal formados
# -------------------------------------------------------
$iptables -A INPUT -i $IF_EXTERNA -m unclean -j LOG --log-level 6 --log-prefix "FIRE: pacote mal formado: "
$iptables -A INPUT -i $IF_EXTERNA -m unclean -j DROP
# Aceita os pacotes que realmente devem entrar
# -------------------------------------------------------
$iptables -A INPUT -i ! $IF_EXTERNA -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
# Proteção contra trinoo
# -------------------------------------------------------
$iptables -N TRINOO
$iptables -A TRINOO -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "FIRE: trinoo: "
$iptables -A TRINOO -j DROP
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 27444 -j TRINOO
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 27665 -j TRINOO
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 31335 -j TRINOO
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 34555 -j TRINOO
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 35555 -j TRINOO
# Proteção contra tronjans
# -------------------------------------------------------
$iptables -N TROJAN
$iptables -A TROJAN -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "FIRE: trojan: "
$iptables -A TROJAN -j DROP
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 666 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 666 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 4000 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 6000 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 6006 -j TROJAN
$iptables -A INPUT -p TCP -i $IF_EXTERNA --dport 16660 -j TROJAN
# Proteção contra worms
# -------------------------------------------------------^M
$iptables -A FORWARD -p tcp --dport 135 -i $IF_INTERNA -j REJECT
# Proteção contra syn-flood
# -------------------------------------------------------
$iptables -A FORWARD -p tcp --syn -m limit --limit 2/s -j ACCEPT
# Proteção contra ping da morte
# -------------------------------------------------------
$iptables -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# Proteção contra port scanners
# -------------------------------------------------------^M
$iptables -N SCANNER
$iptables -A SCANNER -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "FIRE: port scanner: "
$iptables -A SCANNER -j DROP
$iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL NONE -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL ALL -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL FIN,SYN -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -i $IF_EXTERNA -j SCANNER
$iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -i $IF_EXTERNA -j SCANNER
# Loga tentativa de acesso a determinadas portas
# -------------------------------------------------------
$iptables -A INPUT -p tcp --dport 21 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: ftp: "
$iptables -A INPUT -p tcp --dport 23 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: telnet: "
$iptables -A INPUT -p tcp --dport 25 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: smtp: "
$iptables -A INPUT -p tcp --dport 80 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: http: "
$iptables -A INPUT -p tcp --dport 110 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: pop3: "
$iptables -A INPUT -p udp --dport 111 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: rpc: "
$iptables -A INPUT -p tcp --dport 113 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: identd: "
$iptables -A INPUT -p tcp --dport 137:139 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: samba: "
$iptables -A INPUT -p udp --dport 137:139 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: samba: "
$iptables -A INPUT -p tcp --dport 161:162 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: snmp: "
$iptables -A INPUT -p tcp --dport 6667:6668 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: irc: "
$iptables -A INPUT -p tcp --dport 5005 -i $IF_EXTERNA -j LOG --log-level 6 --log-prefix "FIRE: squid: "
## teste paginas gw
$iptables -t nat -A PREROUTING -s 192.168.10.0/24 -d 10.2.111.1 -j ACCEPT
$iptables -t nat -A PREROUTING -s $10.2.111.201 -j ACCEPT
$iptables -t nat -A PREROUTING -s 10.2.113.0/24 -d 10.2.111.201 -j ACCEPT
#################################################
# Tabela NAT
#################################################
# Ativa mascaramento de saída
# -------------------------------------------------------
$iptables -A POSTROUTING -t nat -o $IF_EXTERNA -j MASQUERADE
# Acesso ao Acesso Digital:
$iptables -t nat -I PREROUTING -p tcp -d 200.185.36.0 -j ACCEPT
$iptables -I FORWARD -p tcp -d 200.185.36.0 -j ACCEPT
$iptables -A FORWARD -s 10.2.113.7 -d 200.185.36.0/24 -j ACCEPT
$iptables -A FORWARD -s 10.2.113.0/24 -d 200.185.0.0/24 -j ACCEPT
# Proxy
# -------------------------------------------------------
$iptables -t nat -A PREROUTING -i $IF_INTERNA -p tcp --dport 80 -j REDIRECT --to-port 5005
$iptables -t nat -A PREROUTING -i $IF_INTERNA -p tcp --dport 8080 -j REDIRECT --to-port 5005
# Redireciona portas na própria máquina
# -------------------------------------------------------
$iptables -A FORWARD -p tcp --dport 25 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 110 -j ACCEPT
#$iptbales -A FORWARD -p tcp --sport 110 -j ACCEPT
$iptables -A FORWARD -p tcp --dport 587 -j ACCEPT
# Bloqueio de conteudo
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8192 --string "radio" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8192 --string "orkut.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8192 --string "globoesporte.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "globoesporte.globo.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8192 --string "lance.com.br" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "gazetaesportiva.net" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "runonce.msn.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "ig.com.br" -j DROP
# $iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "uol.com.br" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "sportv.globo.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "globo.com" -j DROP
# $iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "g.live.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "lance.com.br" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "lancenet.com.br" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "mail.live.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "login.live.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "live.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "meebo.com" -j DROP
# $iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "hotmail.com" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "ranchovacaloca.com.br" -j DROP
$iptables -I OUTPUT -o eth1 -m string --algo kmp --from 1 --to 8182 --string "gateway.edge.messenger.live.com" -j DROP