Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # !/bin/bash
- ###################
- ##### Funcoes #####
- ###################
- # Comando: Desativando Firewall
- Configuracoes()
- {
- # Tabela: NAT
- iptables -t nat -P INPUT ACCEPT
- iptables -t nat -P OUTPUT ACCEPT
- iptables -t nat -P FORWARD ACCEPT
- }
- Regra_Lista()
- {
- # Apresentacao
- clear
- echo ""
- echo -e "\033[01;37m ---------------------- \033[01;37m"
- echo -e "\033[01;36m * Listagem de regras * \033[01;37m"
- echo -e "\033[01;37m ---------------------- \033[01;37m"
- echo -e ""
- # Comando: Listagem de regras detalhadas + sequencia
- iptables -t nat -nvL --line-number
- echo -e "\n\033[01;31m --------------------------------------------------------------------- \033[01;37m\n"
- # Comando: Listagem de regras em sequencia
- iptables -t nat -L --line-number
- echo -e "\n\033[01;31m --------------------------------------------------------------------- \033[01;37m\n"
- }
- Regra_Limpeza()
- {
- # Apresentacao
- clear
- echo ""
- echo -e "\033[01;37m ---------------------- \033[01;37m"
- echo -e "\033[01;36m * Regras reiniciadas * \033[01;37m"
- echo -e "\033[01;37m ---------------------- \033[01;37m"
- echo ""
- # Comando: Limpando memoria [flush]
- iptables -t nat -X
- iptables -t nat -F
- }
- Regra_Deletar()
- {
- # Apresentacao
- clear
- echo ""
- echo -e "\033[01;37m -------------------- \033[01;37m"
- echo -e "\033[01;36m * Delecao de regra * \033[01;37m"
- echo -e "\033[01;37m -------------------- \033[01;37m"
- echo ""
- # Entrada de dados
- echo -e -n "\033[01;35m - Posicao: \033[01;37m"
- read pos
- # Comando: Deletar regra pela posicao
- iptables -t nat -D POSTROUTING $pos
- iptables -t nat -D PREROUTING $pos
- }
- Liberar_Internet()
- {
- # Apresentacao
- clear
- echo ""
- echo -e "\033[01;37m -------------------- \033[01;37m"
- echo -e "\033[01;36m * Liberar Internet * \033[01;37m"
- echo -e "\033[01;37m -------------------- \033[01;37m"
- echo ""
- # Entrada de dados
- echo -e "\033[01;36m * Interface * \033[01;37m"
- ifconfig
- echo ""
- # Entrada de dados
- echo -e -n "\033[01;35m - Interface de rede: \033[01;37m"
- read interface
- # Comando: Deletar regra pela posicao
- iptables -t nat -A POSTROUTING -o $interface -j MASQUERADE
- echo "1" > /proc/sys/net/ipv4/ip_forward
- }
- Redirecionamento_Porta()
- {
- # Apresentacao
- clear
- echo ""
- echo -e "\033[01;37m ------------------------------ \033[01;37m"
- echo -e "\033[01;36m * Redirecionamento de portas * \033[01;37m"
- echo -e "\033[01;37m ------------------------------ \033[01;37m"
- echo ""
- # IP [destino] = Nossa maquina
- echo -e -n "\033[01;36m - IP [destino]: \033[01;37m"
- read ip_destino
- echo ""
- # Porta origem = 22
- echo -e -n "\033[01;36m - Porta [servico]: \033[01;37m"
- read porta_servico
- echo ""
- # IP [origem] = Maquina alvo
- echo -e -n "\033[01;36m - IP [origem]: \033[01;37m"
- read ip_origem
- echo ""
- # Porta Alvo = 2200
- echo -e -n "\033[01;36m - Porta [mascarada]: \033[01;37m"
- read porta_mascarada
- echo ""
- # Comando: Redirecionamento de porta
- iptables -t nat -A PREROUTING -d $ip_destino -p TCP --dport $porta_mascarada -j DNAT --to $ip_origem:$porta_servico
- }
- ####################
- ##### IPTABLES #####
- ####################
- # Configuracao
- Configuracoes
- # Estrutura em loop
- while (( 1 ))
- do
- # Menu
- clear
- echo -e "\033[01;36m --------------- DATA --------------- \033[01;37m"
- echo -e "\033[01;32m * Num: $(date +%d) \033[01;37m"
- echo -e "\033[01;31m * Dia: $(date +%a) \033[01;37m"
- echo -e "\033[01;33m * Mes: $(date +%b) \033[01;37m"
- echo -e "\033[01;35m * Ano: $(date +%Y) \033[01;37m"
- echo -e "\033[01;36m ------------------------------------ \033[01;37m"
- echo ""
- echo -e "\033[01;37m ################################# FIREWALL ################################## \033[01;37m\n"
- echo -e "\033[01;33m [1] Regras [lista] \033[01;37m"
- echo -e "\033[01;33m [2] Regras [limpeza] \033[01;37m"
- echo -e "\033[01;33m [3] Regras [deletar] \033[01;37m"
- echo -e ""
- echo -e "\033[01;34m [4] Liberar [internet] \033[01;37m"
- echo -e "\033[01;35m [5] Redirecionamento [porta] \033[01;37m"
- echo ""
- echo -e "\033[01;37m ############################################################################# \033[01;37m\n"
- echo -e -n "\n\033[01;34m + Opc: \033[01;37m"
- read opc
- echo ""
- # Estrutura em escolha
- case $opc in
- 1)
- Regra_Lista;;
- 2)
- Regra_Limpeza;;
- 3)
- Regra_Deletar;;
- 4)
- Liberar_Internet;;
- 5)
- Redirecionamento_Porta;;
- *)
- ;;
- esac
- echo -e "\n\033[01;32m =-=-= Press [ENTER] =-=-= \033[01;37m\n"
- read
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement