Configurando script de inicialização no openSUSE
Publicado por Wagner Souza em 11/03/2016
[ Hits: 8.489 ]
Blog: https://medium.com/@souzaw
#!/bin/bash
#
# firewall Start iptables firewall
#
# chkconfig: 2345 08 92
# description: Starts, stops and saves iptables firewall
#
# Source function library.
. /etc/init.d/functions
iniciar(){
#------------- [ Configurações Gerais ] -------------
# Definição das configurações de rede
WAN=enp0s3
LAN=enp0s8
REDE="192.168.10.0"
MASK="255.255.255.0"
# Carregamento de módulos
modprobe ip_tables
modprobe ip_conntrack
modprobe iptable_filter
modprobe iptable_mangle
modprobe iptable_nat
modprobe ipt_LOG
modprobe ipt_limit
modprobe ipt_state
modprobe ipt_REDIRECT
modprobe ipt_owner
modprobe ipt_REJECT
modprobe ipt_MASQUERADE
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
echo "--> Carregamento de módulos [ OK ]"
# Limpa as regras
iptables -X
iptables -Z
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -F -t nat
iptables -F -t mangle
echo "--> Limpando as chains [ OK ]"
# Politicas padrão
iptables -t filter -P INPUT DROP
iptables -t filter -P OUTPUT DROP
iptables -t filter -P FORWARD DROP
echo "--> Definicao das policies [ OK ]"
# Compartilhar a internet
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE
echo "--> Compartilhamento da internet [ OK ]"
#---------------------- [ FIM ] ----------------------
#------------------- [ Liberações ] ------------------
# Liberando a conexão loopbak
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
echo "--> Liberando a interface de loopback [ OK ]"
# Permitindo acesso SSH
iptables -t filter -A INPUT -p tcp --dport 22 -j LOG --log-level 6 --log-prefix "SSH: "
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --sport 22 -j ACCEPT
echo "--> Permitindo acesso SSH [ OK ]"
# Liberar acesso do servidor a internet
iptables -t filter -A INPUT -m multiport -p tcp --sport 80,443,53,20,21 -j ACCEPT
iptables -t filter -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t filter -A INPUT -p udp --sport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
echo "--> Liberando a internet para o servidor [ OK ]"
# Liberar o servidor DHCP
iptables -t filter -A INPUT -m multiport -p tcp --dport 67,68 -j ACCEPT
iptables -t filter -A INPUT -m multiport -p udp --dport 67,68 -j ACCEPT
# Liberação de portas TCP para a rede local
PORTAS_LIBERADAS="20 21 25 53 80 81 110 443 465 587 995 993"
for i in $PORTAS_LIBERADAS
do
iptables -t filter -A FORWARD -s $REDE/$MASK -p tcp --dport $i -j ACCEPT
iptables -t filter -A FORWARD -d $REDE/$MASK -p tcp --sport $i -j ACCEPT
done
# Liberação de portas UDP para a rede local
PORTAS_LIBERADAS="20 21 53 587 993 465"
for i in $PORTAS_LIBERADAS
do
iptables -t filter -A FORWARD -s $REDE/$MASK -p udp --dport $i -j ACCEPT
iptables -t filter -A FORWARD -d $REDE/$MASK -p udp --sport $i -j ACCEPT
done
echo "--> Liberando portas TCP/UDP para a LAN [ OK ]"
# Liberando ICMP para o servidor e a rede local
iptables -t filter -I INPUT -p icmp --icmp-type echo-reply -j ACCEPT
iptables -t filter -I FORWARD -p icmp --icmp-type echo-reply -j ACCEPT
echo "--> Liberando o ICMP [ OK ]"
#---------------------- [ FIM ] ----------------------
#-------------- [ Regras de Proteção ] --------------
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 1 > /proc/sys/net/ipv4/conf/default/rp_filter
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
iptables -t filter -A INPUT -m state --state INVALID -j DROP
iptables -t filter -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -t filter -A FORWARD -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -t filter -A FORWARD -m state -p icmp --state INVALID -j DROP
# Impedindo ataque Port Scanners na rede e no Firewall
iptables -t filter -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT
iptables -t filter -I INPUT -p udp --dport 33435:33525 -j LOG --log-level info --log-prefix 'SCANNERS DROPADO>'
iptables -t filter -A INPUT -p udp --dport 33435:33525 -j DROP
iptables -t filter -I FORWARD -p udp --dport 33435:33525 -j LOG --log-level info --log-prefix 'SCANNERS DROPADO NA REDE>'
iptables -t filter -A FORWARD -p udp --dport 33435:33525 -j DROP
# Bloquear NetBus na rede
iptables -t filter -I INPUT -p tcp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS >'
iptables -t filter -A INPUT -p tcp --dport 12345 -j DROP
iptables -t filter -I INPUT -p udp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS UDP>'
iptables -t filter -A INPUT -p udp --dport 12345 -j DROP
iptables -t filter -I FORWARD -p tcp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS NA REDE>'
iptables -t filter -A FORWARD -p tcp --dport 12345 -j DROP
iptables -t filter -I FORWARD -p udp --dport 12345 -j LOG --log-level info --log-prefix 'NETBUS UDP>'
iptables -t filter -A FORWARD -p udp --dport 12345 -j DROP
echo "--> Aplicando regras de segurança [ OK ]"
#---------------------- [ FIM ] ----------------------
}
parar(){
iptables -F
iptables -t nat -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
echo 0 > /proc/sys/net/ipv4/ip_forward
echo "Regras de firewall e compartilhamento desativados"
}
case "$1" in
"start") iniciar ;;
"stop") parar ;;
"restart") parar; iniciar ;;
*) echo "Use os parâtros start ou stop"
esac
Baixando arquivos de servidores FTP via linha de comando
Limitar acesso de mais de um usuário via SSH
Guias das Melhores Práticas de Segurança para GNU/Linux
Configurando o xorg.conf no Ubuntu - II
Instalação do tigervnc com certificado SSL
Como criar um lançador do Nautilus no painel do Ubuntu
Alterando a porta do serviço SSH
Instalando e Atualizando o ClamAV no Ubuntu 11.04
Monitorando o Preço do Bitcoin ou sua Cripto Favorita em Tempo Real com um Widget Flutuante
IA Turbina o Desktop Linux enquanto distros renovam forças
Como extrair chaves TOTP 2FA a partir de QRCODE (Google Authenticator)
Como realizar um ataque de força bruta para desobrir senhas?
Como usar Gpaste no ambiente Cinnamon
Atualizando o Fedora 42 para 43
Atalho para usar interrogação (0)
VOL já não é mais como antes? (12)
Scripts ou binários [RESOLVIDO] (4)
Pergunta: Meu teclado não está respondendo direito como e consertar? ... (4)









