Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.39 KB | None | 0 0
  1.  struct pseudo_tcph *ps_tcph = (struct pseudo_tcph *)((char*)tcp - sizeof(struct pseudo_tcph));
  2.             ps_tcph->ip_src = inet_addr(addr);
  3.             ps_tcph->ip_dst = inet_addr(scanned_computer);
  4.             ps_tcph->zero = 0;//always zero
  5.             ps_tcph->protocol = 6;// = 6;//for tcp
  6.             ps_tcph->tcp_len = htons(sizeof(struct tcphdr));
  7.             //ps_tcph->tcp = tcp;
  8.             /*******************************************************************
  9.              * Title: rawtcp.c
  10.              * Date: 20.4.2019
  11.              * Code version:
  12.              * Availability: https://www.tenouk.com/Module43a.html
  13.             ********************************************************************/
  14.                 tcp->th_sport = htons(my_beautiful_port);
  15.                 tcp->th_dport = htons(i);
  16.                 tcp->th_seq = htonl(1);
  17.                 tcp->th_ack = 0;
  18.                 //tcp->th_offx2 = 5;
  19.                 tcp->th_ack = 0;
  20.                 tcp->th_win = htons(32767);
  21.                 tcp->th_sum = 0; // here NOT Done by kernel --> pseudo header for this reason
  22.                 tcp->th_urp = 0;
  23.                 tcp->th_flags = TH_SYN;
  24.  
  25.                 din.sin_port = htons(i);
  26.  
  27.         //      iph->ip_sum = csum((unsigned short *)buffer,
  28. //                              (sizeof(struct ip) + sizeof(struct tcphdr)));
  29.                 tcp->th_sum = csum((unsigned short *)ps_tcph, sizeof(struct pseudo_tcph) + sizeof(struct tcphdr));
  30.                 iph->ip_sum = csum((unsigned short *)buffer, iph->ip_len >> 1);
  31.         // IP structure
  32.         iph->ip_hl = 5;
  33.         iph->ip_v = 4;
  34.         iph->ip_tos = 16;
  35.         iph->ip_len = sizeof(struct ip) + sizeof(struct tcphdr);
  36.         iph->ip_id = htonl(54321);
  37.         iph->ip_off = 0;
  38.         iph->ip_ttl = 64;
  39.         iph->ip_p = 6; // TCP
  40.         iph->ip_sum = 0; // Done by kernel
  41.         // Source IP, modify as needed, spoofed, we accept through command line argument
  42.         iph->ip_src.s_addr = inet_addr(addr);
  43.         // Destination IP, modify as needed, but here we accept through command line argument
  44.         iph->ip_dst.s_addr = inet_addr(scanned_computer);
  45.         iph->ip_len = sizeof(struct ip) + sizeof(struct tcphdr);
  46.  
  47.                 // Inform the kernel do not fill up the headers' structure, we fabricated our own
  48.                 if(setsockopt(sendfd, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement