Segurança · 7 min read · Jan 30, 2026

Chkrootkit-Portsentry-Howto

Chkrootkit-Portsentry-Howto

Versão 1.0
Autor: Falko Timme

Este documento descreve como instalar chkrootkit e portsentry. Deve funcionar (talvez com pequenas alterações em relação a caminhos etc.) em todos os sistemas operacionais *nix.

Chkrootkit “é uma ferramenta para verificar localmente sinais de um rootkit” (de http://www.chkrootkit.org).

“As ferramentas Sentry fornecem serviços de segurança em nível de host para a plataforma Unix. PortSentry, Logcheck/LogSentry e HostSentry protegem contra varreduras de portas, automatizam a auditoria de arquivos de log e detectam atividades de login suspeitas de forma contínua” (de http://sourceforge.net/projects/sentrytools/).

Este howto é destinado como um guia prático; não cobre os fundamentos teóricos. Eles são tratados em muitos outros documentos na web.

Este documento vem sem garantia de qualquer tipo!

1 Obter as Fontes

Precisamos do seguinte software: chkrootkit, portsentry e logcheck. Vamos instalar o software a partir do diretório /tmp.

cd /tmp
wget –passive-ftp ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
wget http://heanet.dl.sourceforge.net/sourceforge/sentrytools/portsentry-1.2.tar.gz
wget http://heanet.dl.sourceforge.net/sourceforge/sentrytools/logcheck-1.1.1.tar.gz

2 Instalar Chkrootkit

mv chkrootkit.tar.gz /usr/local/
cd /usr/local/
tar xvfz chkrootkit.tar.gz
ln -s chkrootkit-0.43/ chkrootkit (substitua 0.43 pelo número da versão correta) cd chkrootkit/ make sense*

Agora você encontrará o programa chkrootkit em /usr/local/chkrootkit. Execute-o digitando

cd /usr/local/chkrootkit/ && ./chkrootkit

Sua saída será algo como isto:

| ROOTDIR is `/` Checking `amd`... not found Checking `basename`... not infected Checking `biff`... not infected Checking `chfn`... not infected Checking `chsh`... not infected Checking `cron`... not infected Checking `date`... not infected Checking `du`... not infected Checking `dirname`... not infected Checking `echo`... not infected Checking `egrep`... not infected Checking `env`... not infected Checking `find`... not infected Checking `fingerd`... not found Checking `gpm`... not found Checking `grep`... not infected Checking `hdparm`... not found Checking `su`... not infected Checking `ifconfig`... not infected Checking `inetd`... not infected Checking `inetdconf`... not infected Checking `identd`... not found Checking `init`... not infected Checking `killall`... not infected Checking `ldsopreload`... not infected Checking `login`... not infected Checking `ls`... not infected Checking `lsof`... not infected Checking `mail`... not infected Checking `mingetty`... not found Checking `netstat`... not infected Checking `named`... not infected Checking `passwd`... not infected Checking `pidof`... not infected Checking `pop2`... not found Checking `pop3`... not found Checking `ps`... not infected Checking `pstree`... not infected Checking `rpcinfo`... not infected Checking `rlogind`... not found Checking `rshd`... not found Checking `slogin`... not infected Checking `sendmail`... not infected Checking `sshd`... not infected Checking `syslogd`... not infected Checking `tar`... not infected Checking `tcpd`... not infected Checking `tcpdump`... not infected Checking `top`... not infected Checking `telnetd`... not found Checking `timed`... not found Checking `traceroute`... not found Checking `vdir`... not infected Checking `w`... not infected Checking `write`... not infected Checking `aliens`... no suspect files Searching for sniffer's logs, it may take a while... nothing found Searching for HiDrootkit's default dir... nothing found Searching for t0rn's default files and dirs... nothing found Searching for t0rn's v8 defaults... nothing found Searching for Lion Worm default files and dirs... nothing found Searching for RSHA's default files and dir... nothing found Searching for RH-Sharpe's default files... nothing found Searching for Ambient's rootkit (ark) default files and dirs... nothing found Searching for suspicious files and dirs, it may take a while... /usr/lib/perl/5.6.1/auto/Test/Harness/.packlist /usr/lib/perl/5.6.1/auto/DB_File/.packlist Searching for LPD Worm files and dirs... nothing found Searching for Ramen Worm files and dirs... nothing found Searching for Maniac files and dirs... nothing found Searching for RK17 files and dirs... nothing found Searching for Ducoci rootkit... nothing found Searching for Adore Worm... nothing found Searching for ShitC Worm... nothing found Searching for Omega Worm... nothing found Searching for Sadmind/IIS Worm... nothing found Searching for MonKit... nothing found Searching for Showtee... nothing found Searching for OpticKit... nothing found Searching for T.R.K... nothing found Searching for Mithra... nothing found Searching for OBSD rk v1... nothing found Searching for LOC rootkit ... nothing found Searching for Romanian rootkit ... nothing found Searching for Suckit rootkit ... nothing found Searching for Volc rootkit ... nothing found Searching for Gold2 rootkit ... nothing found Searching for TC2 Worm default files and dirs... nothing found Searching for Anonoying rootkit default files and dirs... nothing found Searching for ZK rootkit default files and dirs... nothing found Searching for ShKit rootkit default files and dirs... nothing found Searching for AjaKit rootkit default files and dirs... nothing found Searching for zaRwT rootkit default files and dirs... nothing found Searching for anomalies in shell history files... nothing found Checking `asp`... not infected Checking `bindshell`... not infected Checking `lkm`... nothing detected Checking `rexedcs`... not found Checking `sniffer`... eth0: not promisc and no PF_PACKET sockets eth0:0: not promisc and no PF_PACKET sockets eth0:1: not promisc and no PF_PACKET sockets eth0:2: not promisc and no PF_PACKET sockets eth0:3: not promisc and no PF_PACKET sockets eth0:4: not promisc and no PF_PACKET sockets Checking `w55808`... not infected Checking `wted`... nothing deleted Checking `scalper`... not infected Checking `slapper`... not infected Checking `z2`... nothing deleted |

Se um worm, rootkit, etc. for encontrado, isso é indicado pela string INFECTADO (em letras maiúsculas).

Se você quiser receber a saída do chkrootkit uma vez por dia por e-mail às 3 da manhã, pode colocar a seguinte linha no arquivo cron do root (a localização depende da sua distribuição; no Debian está em /var/spool/cron/crontabs/root; você também pode encontrá-lo em /var/spool/cron/tabs/root ou algo semelhante):

0 3 (cd /usr/local/chkrootkit; ./chkrootkit 2>&1 | mail -s “chkrootkit output” [email protected])*

Então execute

chmod 600 /var/spool/cron/crontabs/root
/etc/init.d/cron restart

3 Instalar Portsentry

cd /tmp
tar xvfz portsentry-1.2.tar.gz
cd portsentry_beta/
make linux
make install

Portsentry será instalado em /usr/local/psionic/portsentry/.

Edite /usr/local/psionic/portsentry/portsentry.conf e especifique as portas que você deseja que portsentry proteja:

| # Descomente isso se você for realmente exigente: #TCP_PORTS="1,7,9,11,15,70,79,80,109,110,111,119,138,139,143,512,513,514,515,540,635,1080,1524,2000,[...]" #UDP_PORTS="1,7,9,66,67,68,69,111,137,138,161,162,474,513,517,518,635,640,641,666,700,2049,31335,[...]" # # Use isso se você apenas quiser estar ciente: TCP_PORTS="1,11,15,79,111,119,143,540,635,1080,1524,2000,5742,6667,12345,12346,20034,27665,31337,[...]" UDP_PORTS="1,7,9,69,161,162,513,635,640,641,700,37444,34555,31335,32770,32771,32772,32773,32774,[...]" # # Use isso para apenas o básico #TCP_PORTS="1,11,15,110,111,143,540,635,1080,1524,2000,12345,12346,20034,32771,32772,32773,32774,[...]" #UDP_PORTS="1,7,9,69,161,162,513,640,700,32770,32771,32772,32773,32774,31337,54321" |

Deve ser portas que não estão em uso no sistema. Por exemplo, se você usar IMAP (porta 143 TCP) no servidor, deve remover 143 da lista acima. O restante do portsentry.conf está bem comentado, mas normalmente os valores padrão devem funcionar.

Agora precisamos criar um script de inicialização para portsentry (/etc/init.d/portsentry). Vamos executar portsentry em modo stealth avançado, pois é a maneira mais poderosa de detectar varreduras de portas:

| #!/bin/bash case "$1" in start) echo "Iniciando Portsentry..." ps ax | grep -iw '/usr/local/psionic/portsentry/portsentry -atcp' | grep -iv 'grep' > /dev/null if [ $? != 0 ]; then /usr/local/psionic/portsentry/portsentry -atcp fi ps ax | grep -iw '/usr/local/psionic/portsentry/portsentry -audp' | grep -iv 'grep' > /dev/null if [ $? != 0 ]; then /usr/local/psionic/portsentry/portsentry -audp fi echo "Portsentry agora está em funcionamento!" ;; stop) echo "Desligando Portsentry..." array=(`ps ax | grep -iw '/usr/local/psionic/portsentry/portsentry' | grep -iv 'grep' \ | awk '{print $1}' | cut -f1 -d/ | tr ' ' ' '`) element_count=${#array[@]} index=0 while [ "$index" -lt "$element_count" ] do kill -9 ${array[$index]} let "index = $index + 1" done echo "Portsentry parado!" ;; restart) $0 stop && sleep 3 $0 start ;; *) echo "Uso: $0 {start|stop|restart}" exit 1 esac exit 0 |

chmod 755 /etc/init.d/portsentry

Para iniciar portsentry na inicialização, faça o seguinte:

ln -s /etc/init.d/ portsentry /etc/rc2.d/S20 portsentry
ln -s /etc/init.d/
portsentry /etc/rc3.d/S20 portsentry
ln -s /etc/init.d/
portsentry /etc/rc4.d/S20 portsentry
ln -s /etc/init.d/
portsentry /etc/rc5.d/S20 portsentry
ln -s /etc/init.d/
portsentry /etc/rc0.d/K20 portsentry
ln -s /etc/init.d/
portsentry /etc/rc1.d/K20 portsentry
ln -s /etc/init.d/
portsentry /etc/rc6.d/K20 portsentry*

Agora iniciamos portsentry:

/etc/init.d/portsentry start

Por favor, note: Se você executar portsentry, chkrootkit pode reclamar sobre um bindshell infectado:

Checking bindshell… INFECTADO (PORTAS: 31337)

Isso é normal e não é motivo para se preocupar.

4 Instalar Logcheck

cd /tmp
tar xvfz logcheck-1.1.1.tar.gz
cd logcheck-1.1.1/systems/

Agora mude a variável SYSADMIN em logcheck.sh. SYSADMIN é a pessoa que receberá a saída do logcheck por e-mail (isso pode ser um endereço de e-mail ou um usuário no sistema onde você instala o logcheck):

| [...] # SEÇÃO DE CONFIGURAÇÃO PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin # Logcheck é pré-configurado para funcionar na maioria dos sistemas semelhantes ao BSD, no entanto, é # um programa bastante simples e pode precisar de alguma ajuda para funcionar em outros # sistemas. Por favor, verifique os seguintes caminhos de comando para garantir que estão # corretos. # Pessoa para enviar a atividade do log. [email protected] # Caminho completo para o programa logtail. # Este programa é necessário para executar este script e vem com o pacote. LOGTAIL=/usr/local/bin/logtail [...] |

cd ../../
mkdir -p /usr/local/etc/tmp
make

Isso instalará logcheck em /usr/local/etc.

Agora precisamos criar um trabalho cron para executar logcheck periodicamente. Edite o arquivo cron do root (por exemplo, /var/spool/cron/crontabs/root, veja a seção 2 “Instalar Chkrootkit”) e insira a seguinte linha:

0 3 /usr/local/etc/logcheck.sh*

Então execute

chmod 600 /var/spool/cron/crontabs/root
/etc/init.d/cron restart

Isso invocará logcheck uma vez por dia às 3 da manhã. Agora ele informará você sobre eventos incomuns do sistema, violações de segurança, ataques ao sistema, etc. Se o seu sistema estiver exposto diretamente à internet, você notará que há muitas atividades maliciosas na internet, e você terá uma noção de por que a segurança é muito importante.

Links

Chkrootkit: http://www.chkrootkit.org/

Portsentry: http://sourceforge.net/projects/sentrytools/

Localização original deste documento:

http://www.falkotimme.com/howtos/chkrootkit_portsentry/

Share: X/Twitter LinkedIn

Receba novas postagens na sua caixa de entrada

Sem spam. Cancele a assinatura a qualquer momento.