viernes, 26 de septiembre de 2014

Instalación de la sandbox Cuckoo segunda parte

Ahora una vez descargado y descomprimido Cuckoo ya tendréis Cuckoo casi preparado para funcionar, los fichero importantes son cuckoo.py como no, después la carpeta utils y la carpeta conf, donde habrá los ficheros a modificar una vez configurada la maquina virtual con Windows XP, después hablare sobre los ficheros.

Pasemos a la maquina virtual, yo he usado VirtualBox hay mas opciones, VMware o QEmu por ejemplo. Yo daré por supuesto que la maquina virtual con Windows ya esta instalada y configurada ya que esto no trata de como instalar Windows. Hay dos opciones yo usare la mas común para explicar como se configura la maquina virtual para Cuckoo, la primera seria la conflagración por defecto que deja la VirtualBox con su IP para navegar por Internet y demás la segunda seria como adaptador anfitrión no se conecta a Internet pero por ahora evita problemas ya que la muestra queda aislada dentro de la maquina, yo usare la segunda que es la recomendada por Cuckoo, como lo queráis hacer va por vuestra cuenta.

Vamos a 
Archivo -> Preferencias -> Red



Imagen vboxnet0 



Le dais aceptar y vamos a configuración de la maquina XP, red y configuramos modo anfitrión y queda como la imagen de abajo.



Imagen como tiene que quedar el interfaz de red

Una vez hecho esto creamos una carpeta en nuestro carpeta home/usuario de Linux, la utilizaremos para compartir ficheros entre Cuckoo u otros. Una vez creada volvéis a la maquina virtual configuración -> Carpetas Compartidas -> Símbolo + -> ruta donde habéis creado la carpeta compartida, algo parecido a lo de abajo.


Carpeta compartida con Linux






Lo siguiente es ir a Dispositivos e instalar "guest additions", esto os permitirá desde Windows poder compartir carpetas o sea la carpeta que habéis creado en Linux.


Una vez creado esto, copiar la siguientes reglas de IPTABLES en Linux esto permite comunicarse las dos redes la de Linux y la de Windows ya que si os fijáis en Linux será 192.168.1.x o la que tengáis y en Windows debería ser 192.168.56.101 si no es así algo no habéis hecho bien, ya que tiene que ser 101 o 102, a lo que íbamos la reglas de iptables.



iptables -A FORWARD -o eth0 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT

iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

iptables -A POSTROUTING -t nat -j MASQUERADE




Ahora hacemos ping a Xp desde Linux y tiene que enviar paquetes. Una vez hecho esto vamos a Windows e instalamos Python 2.7,Acrobat Reader y Office y en el menú  de la  maquina virtuales,Dispositivos -> Guest Additions, lo instalamos también, eso nos habilita la carpeta compartida con Linux a para poder verla, además puedes instalar  todo lo que creáis necesario.

Ahora volvemos a Linux vamos a la carpeta cuckoo -> agent y copiamos el fichero agent.py después volvemos a Windows y vamos a Inicio -> Programas -> Botón derecho -> Carpeta Inicio -> Abrir, alli pegamos el fichero agent.py para que al arrancar Windows lo haga automaticamente, podéis dejar con la extensión py o cambiar pyw, la primera muestra una pantalla shell que el agente esta preparado para recibir conexiones, la segunda no mostrara nada. Ahora reiniciad Windows y os tiene que quedar como la imagen de abajo.


Una vez Agent.py se ha ejecutado de forma automatica



Bien ahora ya toca la parte final con Windows, vamos a la intefaz de administrador de maquinas virtuales y le dais a INSTANTANEA sin cerrar la maquina XP, pulsáis sobre el icono de la cámara de fotos os preguntara un nombre poned el que queráis, yo tengo "SNAPSHOT1".


Snapshot de la maquina virtual



Tiene que quedar como la imagen de arriba. Ahora apagamos la maquina con XP y un vez apagada vamos a INSTANTÁNEA otra vez, pero esta vez le dais al icono de al lado de la cámara "RESTAURAR INSTANTÁNEA", desmarcamos la opción que os preguntara "Crear instantánea del estado de la maquina" y pulsáis aceptar, vereis que el estado de la maquina XP pasa de apagado a guaradado.

Con Windows y hemos acabado, ahora volvemos a Linux a la carpeta Cuckoo -> conf allí vamos a editar dos ficheros, se tendrían que editar mas pero para no complicar la cosa solo haremos dos con eso ya funcionara, serán:

Cuckoo.conf y virtualbox.conf, hay mas ficheros como reporting.conf para decirle a cuckoo donde debe guardar los reportes y que base de datos debe usar, como he dicho para no complicar la cosa no voy hacerlo. Voy ha copiar los ficheros tal cual los tengo configurados remarcando las partes importantes.

____________________________________________________________


[cuckoo]
# Enable or disable startup version check. When enabled, Cuckoo will connect
# to a remote location to verify whether the running version is the latest
# one available.
version_check = off

# If turned on, Cuckoo will delete the original file after its analysis
# has been completed.
delete_original = off

# If turned on, Cuckoo will delete the copy of the original file in the
# local binaries repository after the analysis has finished. (On *nix this
# will also invalidate the file called "binary" in each analysis directory,
# as this is a symlink.)
delete_bin_copy = off

# Specify the name of the machinery module to use, this module will
# define the interaction between Cuckoo and your virtualization software
# of choice.
machinery = virtualbox

# Enable creation of memory dump of the analysis machine before shutting
# down. Even if turned off, this functionality can also be enabled at
# submission. Currently available for: VirtualBox and libvirt modules (KVM).
memory_dump = on

# Enable automatically re-schedule of "broken" tasks each startup.
# Each task found in status "processing" is re-queued for analysis.
reschedule = off

# Enable processing of results within the main cuckoo process.
# This is the default behavior but can be switched off for setups that
#  require high stability and process the results in a separate task.
process_results = on

# Limit the amount of analysis jobs a Cuckoo process goes through.
# This can be used together with a watchdog to mitigate risk of memory leaks.
max_analysis_count = 0

# Minimum amount of free space (in MB) available before starting a new task. 
# This tries to avoid failing an analysis because the reports can't be written 
# due out-of-diskspace errors. Setting this value to 0 disables the check.
# (Note: this feature is currently not supported under Windows.)
freespace = 64

# Temporary directory containing the files uploaded through Cuckoo interfaces
# (web.py, api.py, Django web interface).
tmppath = /tmp

[resultserver]
# The Result Server is used to receive in real time the behavioral logs
# produced by the analyzer.
# Specify the IP address of the host. The analysis machines should be able
# to contact the host through such address, so make sure it's valid.
# NOTE: if you set resultserver IP to 0.0.0.0 you have to set the option
# `resultserver_ip` for all your virtual machines in machinery configuration.
ip = 192.168.56.1

# Specify a port number to bind the result server on.
port = 2042

# Should the server write the legacy CSV format?
# (if you have any custom processing on those, switch this on)
store_csvs = off

# Maximum size of uploaded files from VM (screenshots, dropped files, log)
# The value is expressed in bytes, by default 10Mb.
upload_max_size = 10485760

[processing]
# Set the maximum size of analysis's generated files to process.
# This is used to avoid the processing of big files which can bring memory leak.
# The value is expressed in bytes, by default 100Mb.
analysis_size_limit = 104857600

# Enable or disable DNS lookups.
resolve_dns = on

[database]
# Specify the database connection string.
# Examples, see documentation for more:
# sqlite:///foo.db
#  postgresql://foo:bar@localhost:5432/mydatabase
# mysql://foo:bar@localhost/mydatabase
# If empty, default is a SQLite in  db/cuckoo.db.
connection = 

# Database connection timeout in seconds.
# If empty, default is set to 60 seconds.
timeout =

[timeouts]
# Set the default analysis timeout expressed in seconds. This value will be
# used to define after how many seconds the analysis will terminate unless
# otherwise specified at submission.
default = 120

# Set the critical timeout expressed in seconds. After this timeout is hit
# Cuckoo will consider the analysis failed and it will shutdown the machine
# no matter what. When this happens the analysis results will most likely
# be lost. Make sure to have a critical timeout greater than the
# default timeout.
critical = 600

# Maximum time to wait for virtual machine status change. For example when
# shutting down a vm. Default is 300 seconds.
vm_state = 300
_________________________________________________________________________________
Ahora pasamos al virtualbox.conf:


[virtualbox]
# Specify which VirtualBox mode you want to run your machines on.
# Can be "gui", "sdl" or "headless". Refer to VirtualBox's official
# documentation to understand the differences.
mode = gui
# Path to the local installation of the VBoxManage utility.
path = /usr/bin/VBoxManage
# Specify a comma-separated list of available machines to be used. For each
# specified ID you have to define a dedicated section containing the details
# on the respective machine. (E.g. cuckoo1,cuckoo2,cuckoo3)
machines = XP (Nombre de vuestra maquina Virtual)

[XP] (El nombre de vuestra Maquina Virtual)
# Specify the label name of the current machine as specified in your
# VirtualBox configuration.
label = XP (El nombre de vuestra Maquina Virtual)


# Specify the operating system platform used by current machine
# [windows/darwin/linux].
platform = windows

# Specify the IP address of the current virtual machine. Make sure that the
# IP address is valid and that the host machine is able to reach it. If not,
# the analysis will fail.
ip = 192.168.56.101  (Esta es la ip de vuestra maquina Windows al hacer un ipconfig la de Cuckoo.conf es la que tiene el admnistrador de maquinas virtual para el           Interfaz de red vboxnet0, no confundiros)

# (Optional) Specify the snapshot name to use. If you do not specify a snapshot
# name, the VirtualBox MachineManager will use the current snapshot.
# Example (Snapshot1 is the snapshot name):
  snapshot = snapshot1

# (Optional) Specify the name of the network interface that should be used
# when dumping network traffic from this machine with tcpdump. If specified,
# overrides the default interface specified in cuckoo.conf
# Example (vboxnet0 is the interface name):
# interface = vboxnet0

# (Optional) Specify the IP of the Result Server, as your virtual machine sees it.
# The Result Server will always bind to the address and port specified in cuckoo.conf,
# however you could set up your virtual network to use NAT/PAT, so you can specify here 
# the IP address for the Result Server as your machine sees it. If you don't specify an
# address here, the machine will use the default value from cuckoo.conf.
# NOTE: if you set this option you have to set result server IP to 0.0.0.0 in cuckoo.conf.
# Example:
# resultserver_ip = 192.168.56.1

# (Optional) Specify the port for the Result Server, as your virtual machine sees it.
# The Result Server will always bind to the address and port specified in cuckoo.conf,
# however you could set up your virtual network to use NAT/PAT, so you can specify here
# the port for the Result Server as your machine sees it. If you don't specify a port
# here, the machine will use the default value from cuckoo.conf.
# Example:
# resultserver_port = 2042

# (Optional) Set your own tags. These are comma separated and help to identify
# specific VMs. You can run samples on VMs with tag you require.
# tags = windows_xp_sp3,32_bit,acrobat_reader_6


_____________________________________________________________________

Basicamente esto es todo ya os tendría que funcionar Cuckoo, pero antes quiero hacer hincapíe en algo por si alguien lo ha hecho así y es importante ya que si no no funcionara Cuckoo.

Si alguien ha bajado cuckoo en modo root y lo ha configurado en modo root se dará cuenta que al ejecutar cuckoo le da un error que no encuentra la maquina virtual, eso no es culpa de cuckoo si no que que estais ejecutando todo en modo root y virtualmanager que el comando que permite arrancar las maquinas virtuales y es con el que cucko trabaja y si editáis su código en Python veréis como lo hace, pues lo que deicía virtualmanager no contempla el usuario root, no permite ejecuciones ya que no existe para el ese usuario aunque lo estés usando y si exista lógicamente, así que tenéis que hacerlo todo con vuestro usuario bajar el programa cuckoo, descomprimidlo, etc..., para hacer una prueba si arranca una maquina o no probad esto VboxManage startvm nombre de una maquina virtual que tengáis a parte de la de pruebas, probat con root y sin el veiréis la diferencia. 

Ahora arrancaremos cuckoo primero, desde la carpeta cuckoo teclead

python cuckoo.py o ./cuckoo.py (va a gusto.)

Tiene que quedaros como la imagen de abajo. Bien ahora abrimos otra shell vamos a la carpeta cuckoo -> utils y allí ejecutamos:


Cuckoo una vez iniciado a la espera de analizar algo




python submit.py  /directorioMalware/BichoMalo.exe y veréis en virtualbox como la maquina XP inicia y empieza el análisis del malware.

Para los que quieran entorno grafico esta otra opción, lugar de elegir submit.py ejecutat web.py y dejáis la ventana shell tal cual, ahora vais a vuestro navegador preferido y ponéis en su barra de direcciones:

http://localhost:8080/ 

Os saldrá lo mismo que la imagen de abajo.




Interfaz grafico via web de Cuckoo




Ahí le dais a "Choose file" y "Submit" pasara exactamente lo mismo que cuando ejecutaste submit.py en la shell, cuando acabe de analizar la información vais a Browser el menú de arriba en el interfaz de cuckoo y tendréis la muestra analizada con toda la información que ha podido extraer. Con esto finaliza la post espero que os sea útil y os haya parecido interesante.

Un saludo





No hay comentarios:

Publicar un comentario