shieldscript - Script para defesa básica do seu GNU/Linux
Publicado por Felipe Ruiz Peixoto (última atualização em 07/04/2015)
[ Hits: 3.725 ]
Homepage: https://www.ubuntu.com/
Download 1427907799.shieldscript (versão 2)
Olá, uma das coisas que mais gosto de fazer em um GNU/Linux são scripts, eles facilitam muito a minha vida. :)
Acabei de criar um script para configurar uma proteção básica para meu sistema (Kali). Ele pode ser útil para pessoas que não possuem muito conhecimento em GNU/Linux a fim de se protegerem.
Estou publicando o script aqui para que seja melhorado por quem tiver mais ideias. Vou colocar ele no SourceForge também.
Precisa ter iptables e xterm instalado, e ser executado como superusuário.
Ele instala automaticamente vários pacotes: clamav-daemon, clamav-freshclam, clamtk (não usa), rkhunter, chkrootkit e firestarter (não usa). Veja a seguir um manual de como utilizar o script.
Para começar, abra o terminal, digite o comando su e depois sua senha para usar como superusuário.
Depois é só arrastar e soltar o arquivo para dentro do terminal (ou digitar o caminho até ele) e apertar enter para ver as opções:
Para instalar, use:
# /minhapasta/shieldscript -i
O terminal poderá fazer "uma ou duas" perguntas, uma delas é "Type your net ip (example 123.456.789.123/16):". Então você deve ver qual faixa de IP seu roteador utiliza e colocar aqui no formato mostrado no exemplo. Para facilitar, abra as informações da conexão clicando com o botão direto no ícone de rede perto do relógio. Para o número antes da barra procure sua máscara de sub-rede e troque os números 255 pelos números do seu endereço IP, deixando outros números como estão. Para o número depois da barra, conte quantos números 255 tem sua máscara e multiplique isto por 8. Este método não é correto mas funciona para redes domésticas simples.
No fim da instalação este script vai criar outro chamado "start_my_firewall" que deve ser executado sempre que você fizer seu login, bastando dar dois cliques sobre ele.
Para atualizar os programas de proteção use:
# /minhapasta/shieldscript -u
Para instalar e atualizar em seguida use:
# /minhapasta/shieldscript -iu
Para procurar e remover programas maliciosos do seu sistema e ativar o firewall use:
# /minhapasta/shieldscript -c
Para fazer isso depois de instalar e atualizar use:
# /minhapasta/shieldscript -a
Para "zerar" as configurações de firewall use:
# /minhapasta/shieldscript -f
E para desinstalar tudo use:
# /minhapasta/shieldscript -r
Versão 2 - Enviado por Felipe Ruiz Peixoto em 01/04/2015
Changelog: Nova versão melhorada.
Download 1427907799.shieldscript
#!/bin/bash # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. # ## Version number of the script VERSION=0.3 echo Shieldscript-Anti Hacker Linux Script provides basic protection configuration v. $VERSION echo Need superuser permissions ## Installation function Install(){ echo Installing needed packages apt-get install --fix-missing -y clamav-daemon clamav-freshclam clamtk rkhunter chkrootkit firestarter echo Blocking the ping in the firewall iptables -A INPUT -p icmp --icmp-type echo-request -j DROP echo Blocking port scanners iptables -A INPUT -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST RST -m limit --limit 1/s -j ACCEPT echo Blocking tracertroute iptables -A INPUT -p udp -s 0/0 -i eth1 --dport 33435:33525 -j DROP echo Protecting against attacks, worms and tojans iptables -A INPUT -m state --state INVALID -j DROP iptables -A FORWARD -p tcp --dport 135 -i venet0 -j REJECT iptables -N TROJAN iptables -A TROJAN -m limit --limit 15/m -j LOG --log-level 6 --log-prefix "FIREWALL: trojan: " iptables -A TROJAN -j DROP iptables -A INPUT -p TCP -i venet0 --dport 666 -j TROJAN iptables -A INPUT -p TCP -i venet0 --dport 4000 -j TROJAN iptables -A INPUT -p TCP -i venet0 --dport 6000 -j TROJAN iptables -A INPUT -p TCP -i venet0 --dport 6006 -j TROJAN iptables -A INPUT -p TCP -i venet0 --dport 16660 -j TROJAN echo Avoiding IP Spoofing in the firewall echo 'Type your net ip (example 123.456.789.123/16):' read faixadeip #Bloqueia IP Spoofing para máquinas com interface de rede #iptables -A INPUT -s 10.0.0.0/8 -i eth0 -j DROP #iptables -A INPUT -s 172.16.0.0/8 -i eth0 -j DROP #iptables -A INPUT -s 192.168.0.0/8 -i eth0 -j DROP iptables -A FORWARD -i eth0 ! -s $faixadeip -j DROP #Bloqueia IP Spoofing para máquinas com interface WiFi: #iptables -A INPUT -s 10.0.0.0/8 -i wlan0 -j DROP #iptables -A INPUT -s 172.16.0.0/8 -i wlan0 -j DROP #iptables -A INPUT -s 192.168.0.0/8 -i wlan0 -j DROP iptables -A FORWARD -i wlan0 ! -s $faixadeip -j DROP #Bloqueia IP Spoofing para máquinas com interface com modens ADSL: #iptables -A INPUT -s 10.0.0.0/8 -i ppp0 -j DROP #iptables -A INPUT -s 172.16.0.0/8 -i ppp0 -j DROP #iptables -A INPUT -s 192.168.0.0/8 -i ppp0 -j DROP iptables -A FORWARD -i ppp0 ! -s $faixadeip -j DROP #Garante a navegacao da maquina #iptables -A INPUT -m state -state RELATED,ESTABLISHED -j ACCEPT echo Saving firewall configurations and changing the rc.local mkdir -p /usr/share/shieldscript echo Making backup of your current rc.local, to restore use the option -f cp -f -R /etc/rc.local /usr/share/shieldscript chmod +x /usr/share/shieldscript/rc.local echo Saving your firewall settings iptables-save > /usr/share/shieldscript/conf echo Making the script to enable firewall settings echo '#!/bin/sh' > /usr/share/shieldscript/firescript echo "echo Shieldscript v. $VERSION" >> /usr/share/shieldscript/firescript echo "echo To activate your firewall please input your superuser password" >> /usr/share/shieldscript/firescript echo 'su -c "iptables-restore /usr/share/shieldscript/conf"' >> /usr/share/shieldscript/firescript echo "echo OK" >> /usr/share/shieldscript/firescript echo "echo Press enter to exit" >> /usr/share/shieldscript/firescript echo "read none" >> /usr/share/shieldscript/firescript echo "exit 0" >> /usr/share/shieldscript/firescript chmod +x /usr/share/shieldscript/firescript ## Create a script to start the firewall echo '#!/bin/sh' > start_my_firewall echo 'xterm -e /usr/share/shieldscript/firescript' >> start_my_firewall chmod +x start_my_firewall ## TODO Start firescript at logon #echo Creating shieldscriptfw in init.d to start the firewall #echo '#!/bin/bash' > /etc/init.d/shieldscriptfw #echo '#' >> /etc/init.d/shieldscriptfw #echo '# /etc/init.d/shieldscriptfw' >> /etc/init.d/shieldscriptfw #echo ' ' >> /etc/init.d/shieldscriptfw #echo '### BEGIN INIT INFO' >> /etc/init.d/shieldscriptfw #echo '# Provides: shieldscriptfw' >> /etc/init.d/shieldscriptfw #echo '# Required-Start: $local_fs $syslog' >> /etc/init.d/shieldscriptfw #echo '# Required-Stop: $local_fs $syslog' >> /etc/init.d/shieldscriptfw #echo '# Default-Start: 2 3 4 5' >> /etc/init.d/shieldscriptfw #echo '# Default-Stop: 0 1 6' >> /etc/init.d/shieldscriptfw #echo '# Short-Description: Start shieldscript firewall configuration automatically' >> /etc/init.d/shieldscriptfw #echo '# Description: Start shieldscript firewall configuration' >> /etc/init.d/shieldscriptfw #echo '### END INIT INFO' >> /etc/init.d/shieldscriptfw #echo ' ' >> /etc/init.d/shieldscriptfw #echo ' ' >> /etc/init.d/shieldscriptfw #echo 'case "$1" in' >> /etc/init.d/shieldscriptfw #echo 'start ) xterm /usr/share/shieldscript/firescript ;;' >> /etc/init.d/shieldscriptfw #echo ' ' >> /etc/init.d/shieldscriptfw #echo 'stop ) echo "OK." ;;' >> /etc/init.d/shieldscriptfw #echo ' ' >> /etc/init.d/shieldscriptfw #echo 'restart )echo "OK." ;;' >> /etc/init.d/shieldscriptfw #echo ' ' >> /etc/init.d/shieldscriptfw #echo '* ) echo "Invalid option" ;;' >> /etc/init.d/shieldscriptfw #echo 'esac' >> /etc/init.d/shieldscriptfw #chmod +x /etc/init.d/shieldscriptfw #which update-rc.d #if [ $? = 0 ] #then # update-rc.d shieldscriptfw defaults #else # chkconfig --add shieldscriptfw # chkconfig shieldscriptfw on #fi #echo '#!/bin/sh -e' > /etc/rc.local #echo '# rc.local' >> /etc/rc.local #echo '#' >> /etc/rc.local #echo '# This script is executed at the end of each multiuser runlevel.' >> /etc/rc.local #echo '# Make sure that the script will "exit 0" on success or any other' >> /etc/rc.local #echo '# value on error.' >> /etc/rc.local #echo '#' >> /etc/rc.local #echo '# In order to enable or disable this script just change the execution' >> /etc/rc.local #echo '# bits.' >> /etc/rc.local #echo '#' >> /etc/rc.local #echo '# By default this script does nothing.' >> /etc/rc.local #echo '# Shieldscript firewall' >> /etc/rc.local #echo "xterm /usr/share/shieldscript/firescript" >> /etc/rc.local #echo 'exit 0' >> /etc/rc.local #chmod +x /etc/rc.local echo INSTALLATION FINISHED } Update(){ rkhunter --update freshclam } FirewallReset(){ iptables -F iptables -Z iptables -X mv /usr/share/shieldscript/rc.local /etc chmod +x /etc/rc.local rm -R /usr/share/shieldscript echo Use a opcao -i para refazer o firewall # iptables -P INPUT ACCEPT # iptables -F # iptables -A INPUT -i lo -j ACCEPT # iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT # iptables -A INPUT -p tcp –dport 22 -j ACCEPT # iptables -P INPUT DROP # iptables -P FORWARD DROP # iptables -P OUTPUT ACCEPT # iptables -L -v } Uninstall(){ FirewallReset apt-get remove --fix-missing -y clamav-daemon clamav-freshclam clamtk rkhunter chkrootkit firestarter rm -f -R /usr/share/shieldscript #which update-rc.d #if [ $? = 0 ] #then # update-rc.d -f shieldscriptfw remove #else # chkconfig shieldscriptfw off # chkconfig --del shieldscriptfw #fi #rm -f /etc/init.d/shieldscriptfw echo Shieldscript v. $VERSION uninstalled } Check(){ rkhunter --check chkrootkit clamscan --bell --remove=yes -r -z -i iptables-restore /usr/share/shieldscript/conf } Help(){ echo Syntax: anti-hacker-linux-script [option] echo Options: echo -i ---- install echo -u ---- update echo -c ---- check the system echo -iu ---- install and update echo -a ---- install, update and check echo -r ---- uninstall echo -h ---- show this help text echo -f ---- reset firewall echo -x ---- exit ## Authors echo 'Felipe Ruiz Peixoto "Felipeludo" <feliperuiz.sax.eletronic@gmail.com>' } case $1 in "-h") Help ;; "-u") Update ;; "-c") Check ;; "-i") Install ;; "-iu") Install ; Update ;; "-a") Install ; Update ; Check ;; "-r") Uninstall ;; "-f") FirewallReset ;; "-x") exit 0 ;; *) Help ;; esac
PINGS - Ping para diversos hosts em varios consoles
Como escolher o melhor escalonador de CPU para melhorar o desempenho da máquina
Curiosidade sobre DOOM Guy e Isabelle de Animal Crossing
Inicializando servidor Ubuntu na AWS e rodando apache em Container
Instalando TeamViewer no Debian 12
Conheça o Octopi, outro frontend para o Pacman com acesso ao AUR (Arch Linux e derivados)
Terminal transparente no Debian 12 com interface i3wm usando Xfce4-Terminal e Compton
Ubuntu simplesmente morreu (8)
Como colocar uma assinatura digital em um código compilado ! (2)
Como traduzir todo o nitrogen para BR? (1)
Eu estou com problemas para usar o QBASIC no Dosbox X (1)
Como eu posso logar noutra distro sem subir o sistema? [RESOLVIDO] (5)